criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int k,n;
    cin >> n >> k;
    int t[n];
    long long d[n];
    map<int,long long> mpmax;
    multiset<long long> max;
    multiset<long long> others;
    rep(i,n){
        cin >> t[i] >> d[i];
        auto itr = mpmax.find(t[i]);
        if(itr != mpmax.end()){
            if(mpmax[t[i]] < d[i]){
                auto c = max.erase(mpmax[t[i]]);
                rep(i,c-1){
                    max.insert(mpmax[t[i]]);
                }
                max.insert(d[i]);
                others.insert(mpmax[t[i]]);
                mpmax[t[i]] = d[i];
            }
            else{
                others.insert(d[i]);
            }
        }
        else{
            max.insert(d[i]);
            mpmax[t[i]] = d[i];
        }
    }
    int p = max.size();
    long long sump[p+5];
    sump[0] = 0;
    auto itr = max.end();
    itr--;
    rep(i,p){
        sump[i+1] = sump[i] + *itr;
        itr--;
    }
    int q = others.size();
    long long sumq[q+5];
    sumq[0] = 0;
    itr = others.end();
    itr--;
    rep(i,q){
        sumq[i+1] = sumq[i] + *itr;
        itr--;
    }
    long long ans = 0;
    long long tem;
    /*for(auto itr = max.begin();itr!=max.end();itr++){
        cout << *itr ;
    }
    cout  << endl;
    for(auto itr = others.begin();itr!=others.end();itr++){
        cout << *itr; 
    }
    cout << endl;*/
    if(q.empty()){
        cout << sump[k] << endl;
    }
    else{
        for(int i = min(k,p);i>=1;i--){
            tem = 0;
            tem+=i*i;
            tem+=sump[i];
            if(k-i<=q){
                tem+=sumq[k-i];
            }
            else{
                tem = 0;
            }
            if(tem>ans){
                ans = tem;
            }
        }
        cout << ans << endl;  
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:71:10: error: request for member 'empty' in 'q', which is of non-class type 'int'
   71 |     if(q.empty()){
      |          ^~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int k,n;
    cin >> n >> k;
    int t[n];
    long long d[n];
    map<int,long long> mpmax;
    multiset<long long> max;
    multiset<long long> others;
    rep(i,n){
        cin >> t[i] >> d[i];
        auto itr = mpmax.find(t[i]);
        if(itr != mpmax.end()){
            if(mpmax[t[i]] < d[i]){
                auto c = max.erase(mpmax[t[i]]);
                rep(i,c-1){
                    max.insert(mpmax[t[i]]);
                }
                max.insert(d[i]);
                others.insert(mpmax[t[i]]);
                mpmax[t[i]] = d[i];
            }
            else{
                others.insert(d[i]);
            }
        }
        else{
            max.insert(d[i]);
            mpmax[t[i]] = d[i];
        }
    }
    int p = max.size();
    long long sump[p+5];
    sump[0] = 0;
    auto itr = max.end();
    itr--;
    rep(i,p){
        sump[i+1] = sump[i] + *itr;
        itr--;
    }
    int q = others.size();
    long long sumq[q+5];
    sumq[0] = 0;
    itr = others.end();
    itr--;
    rep(i,q){
        sumq[i+1] = sumq[i] + *itr;
        itr--;
    }
    long long ans = 0;
    long long tem;
    /*for(auto itr = max.begin();itr!=max.end();itr++){
        cout << *itr ;
    }
    cout  << endl;
    for(auto itr = others.begin();itr!=others.end();itr++){
        cout << *itr; 
    }
    cout << endl;*/
    if(q.size()==0){
        cout << sump[k] << endl;
    }
    else{
        for(int i = min(k,p);i>=1;i--){
            tem = 0;
            tem+=i*i;
            tem+=sump[i];
            if(k-i<=q){
                tem+=sumq[k-i];
            }
            else{
                tem = 0;
            }
            if(tem>ans){
                ans = tem;
            }
        }
        cout << ans << endl;  
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:71:10: error: request for member 'size' in 'q', which is of non-class type 'int'
   71 |     if(q.size()==0){
      |          ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int> P;
int n,k,S,cnt,l,r,ans;
P p[111111];
set<int>st;
multiset<int>ml;
signed main(){
	cin>>n>>k;
	rep(i,n){
		cin>>p[i].second>>p[i].first;
		st.insert(p[i].second);
	}
	sort(p,p+n,greater<P>());
	S=st.size();
	st.erase(st.begin(),st.end());
	rep(i,k){
		cnt+=t[i].first;
		ml.insert(p[i].second);
		st.insert(p[i].second);
	}
	l=k-1,r=k;
	ans=st.size()*st.size()+cnt;
	for(int i=st.size();i<min(k,S);i++){//i:種類数
		while(ml.count(p[l].second)==1)l--;
		while(1){
			if(ml.find(p[r].second)==ml.end()){
				cnt+=p[r].first-p[l].first;
				ml.erase(ml.find(p[l].second));
				l--;
				ml.insert(p[r].second);
				break;
			}
			r++;
		}
		ans=max(ans,(i+1)*(i+1)+cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:22: error: 't' was not declared in this scope
   20 |                 cnt+=t[i].first;
      |                      ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int> P;
int n,k,S,cnt,l,r,ans;
P p[111111];
set<int>st;
multiset<int>ml;
signed main(){
	cin>>n>>k;
	rep(i,n){
		cin>>p[i].second>>p[i].first;
		st.insert(p[i].second);
	}
	sort(p,p+n,greater<P>);
	S=st.size();
	st.erase(st.begin(),st.end());
	rep(i,k){
		cnt+=t[i].first;
		ml.insert(p[i].second);
		st.insert(p[i].second);
	}
	l=k-1,r=k;
	ans=st.size()*st.size()+cnt;
	for(int i=st.size();i<min(k,S);i++){//i:種類数
		while(ml.count(p[l].second)==1)l--;
		while(1){
			if(ml.find(p[r].second)==ml.end()){
				cnt+=p[r].first-p[l].first;
				ml.erase(ml.find(p[l].second));
				l--;
				ml.insert(p[r].second);
				break;
			}
			r++;
		}
		ans=max(ans,(i+1)*(i+1)+cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:30: error: expected primary-expression before ')' token
   16 |         sort(p,p+n,greater<P>);
      |                              ^
a.cc:20:22: error: 't' was not declared in this scope
   20 |                 cnt+=t[i].first;
      |                      ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n,k,S,cnt,l,r,ans;
pair<int,int>p[111111];
set<int>st;
multiset<int>ml;
signed main(){
	cin>>n>>k;
	rep(i,n){
		cin>>p[i].second>>p[i].first;
		st.insert(p[i].second);
	}
	sort(p,p+n,greater<P>);
	S=st.size();
	st.erase(st.begin(),st.end());
	rep(i,k){
		cnt+=t[i].first;
		ml.insert(p[i].second);
		st.insert(p[i].second);
	}
	l=k-1,r=k;
	ans=st.size()*st.size()+cnt;
	for(int i=st.size();i<min(k,S);i++){//i:種類数
		while(ml.count(p[l].second)==1)l--;
		while(1){
			if(ml.find(p[r].second)==ml.end()){
				cnt+=p[r].first-p[l].first;
				ml.erase(ml.find(p[l].second));
				l--;
				ml.insert(p[r].second);
				break;
			}
			r++;
		}
		ans=max(ans,(i+1)*(i+1)+cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:28: error: 'P' was not declared in this scope
   15 |         sort(p,p+n,greater<P>);
      |                            ^
a.cc:15:29: error: template argument 1 is invalid
   15 |         sort(p,p+n,greater<P>);
      |                             ^
a.cc:19:22: error: 't' was not declared in this scope
   19 |                 cnt+=t[i].first;
      |                      ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

bool compare(pair<int, int> p1, pair<int, int> p2) {
  return p1.second >= p2.second;
}
int main() {
  int n, k;
  cin>>n>>k;
  pair<int, int> a[n];
  for (int i=0; i<n; i++) {
    int ti, di;
    cin>>ti>>di;
    a[i] = make_pair(ti, di);
  }
  sort(a, a+n, compare);

  long long ans = a[0].second;
  set<int> types;
  types.insert(a[0].first);
  int idx1 = 1;
  int idx2 = -1;
  for (int i=1; i<n; i++) {
    if (types.find(a[i].first) == types.end()) {
      idx2 = i;
      break;
    }
  }
  int cnt = 1;
  while (cnt < k) {
    if (idx2 == -1) {
      ans += a[idx1].second;
      ++idx1;
    }
    else if (idx1 == idx2) {
      types.insert(a[idx1].first);
      int size = types.size();
      ans += a[idx1].second + size*size - (size-1)*(size-1);
      ++idx;
      idx2 = -1;
      for (int i=idx1; i<n; i++) {
        if (types.find(a[i].first) == types.end()) {
          idx2 = i;
          break;
        }
      }
    }
    else {
      int size = types.size();
      long long ans1 = ans + a[idx1].second;
      long long ans2 = ans + a[idx2].second + (size+1)*(size+1) - size*size;
      if (ans1 >= ans2) {
        ans = ans1;
        ++idx1;
      } else {
        ans = ans2;
        types.inert(a[idx2].first);
        idx2 = -1;
        for (int i=idx1; i<n; i++) {
          if (types.find(a[i].first) == types.end()) {
            idx2 = i;
            break;
          }
        }
      }
    }
    ++cnt;
  }
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:41:9: error: 'idx' was not declared in this scope; did you mean 'idx2'?
   41 |       ++idx;
      |         ^~~
      |         idx2
a.cc:59:15: error: 'class std::set<int>' has no member named 'inert'; did you mean 'insert'?
   59 |         types.inert(a[idx2].first);
      |               ^~~~~
      |               insert
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k;
  cin>>n>>k;
  V t(n),d(n);
  rep(i,n)cin>>t[i]>>d[i],t[i]--;
  VP dt(n);
  rep(i,n)dt[i]=m_p(d[i],t[i]);
  RSORT(dt);
  
  int sum=0;
  set<ll> kinds;
  priority_queue<ll,Vec<ll>,greater<ll>> que;
  rep(i,k){
    sum+=dt[i].fi;
    if(kinds.find(dt[i].se)==kinds.end())
      que.push(dt[i].fi);
    kinds.insert(dt[i].se);
  }
  int ans=sum+SZ(kinds)*SZ(kinds);
  for(int i=k;i<n;++i){
    if(!que.empty())break;
    if(kinds.find(dt[i].se)==kinds.end()){
        sum-=que.top();
        que.pop();
        sum+=dt[i].fi;
        kinds.insert(dt[i].se);
    }
    chmax(ans,sum+SZ(kinds)*SZ(kinds));
  }
  out(ans);
  
  
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:74:10: error: no matching function for call to 'chmax(long long int&, long long unsigned int)'
   74 |     chmax(ans,sum+SZ(kinds)*SZ(kinds));
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:41:23: note: candidate: 'template<class T> bool chmax(T&, const T&)'
   41 | template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
      |                       ^~~~~
a.cc:41:23: note:   template argument deduction/substitution failed:
a.cc:74:10: note:   deduced conflicting types for parameter 'const T' ('long long int' and 'long long unsigned int')
   74 |     chmax(ans,sum+SZ(kinds)*SZ(kinds));
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<iostream>
#include<map>
#include<vector>
using namespace std;
int n,k;
map<int ,vector<long long>> mvl;
vector<int>key;

void chmax(long long &a,long long b){if(a<b)a=b;}

long long rec(int j,int var,long long sum,int select){
  //  cout<<j<<endl;
  if(select==k)return var*var+sum;
  if(select>k)return 0;
  if(j==key.size())return 0;
  vector<long long> v=mvl[ key[j] ];
  const int sz=v.size();
  long long res=0;
  for(int i=0;i<sz;++i){
	long long tmp=rec(j+1,(i?var+1:var),sum+v[i],select+i);
	chmax(res,tmp);
  }
  return res;
}

int main(){
  cin>>n>>k;
  vector<pair<long long,long long>>pii(n);
  for(int i=0;i<n;++i)
	cin>>pii[i].second>>pii[i].first;
  sort(pii.rbegin(),pii.rend());
  for(int i=0;i<n;++i){
	long long t=pii[i].second,d=pii[i].first;
	if(mvl[t].empty()){
	  mvl[t].push_back(0);
	  key.push_back(t);
	}
	mvl[t].push_back(d+*(mvl[t].end()-1));
  }

  // for(auto it=mvl.begin();it!=mvl.end();++it){
  // 	cout<<it->first<<':';
  // 	vector<long long> v=it->second;
  // 	for(int i=0;i<v.size();++i)
  // 	  cout<<v[i]<<' ';
  // 	cout<<endl;
  // }

  cout<<rec(0,0,0,0)<<endl;
  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   31 |   sort(pii.rbegin(),pii.rend());
      |   ^~~~
      |   short
Language: C++

#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
#include <numeric>

using namespace std;
using int64 = long long;

struct Sushi
{
    int t;
    int64 d;

    bool operator<(const Sushi &other) const
    {
        return d > other.d;
    }
};

struct LessSushiComp
{
    bool operator()(const Sushi &a, const Sushi &b) const
    {
        return a.d < b.d;
    }
};

struct MoreSushiComp
{
    bool operator()(const Sushi &a, const Sushi &b) const
    {
        return a.d > b.d;
    }
};

constexpr int MaxN = 100000 + 10;
Sushi S[MaxN];

int main()
{
    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        cin >> S[i].t >> S[i].d;
    }

    sort(S, S + n, [](auto & a, auto & b) { return a.d > b.d; });

    unordered_map<int, int> count;
    priority_queue<Sushi, vector<Sushi>, MoreSushiComp> used;
    priority_queue<Sushi, vector<Sushi>, LessSushiComp> remains;
    int64 ans = 0, sum = 0;
    for (int i = 0; i < k; i++)
    {
        used.push(S[i]);
        count[S[i].t]++;
        sum += S[i].d;
    }

    ans = sum + count.size() * count.size();

    for (int i = k; i < n; i++)
    {
        remains.push(S[i]);
    }

    int numKinds = count.size();
    while (true)
    {
        auto TryPop = [](auto & queue, auto pred)
        {
            vector<Sushi> poped;
            bool satisfied = false;
            while (!queue.empty())
            {
                auto sushi = queue.top();
                queue.pop();
                poped.push_back(sushi);

                if (pred(sushi))
                {
                    satisfied = true;
                    break;
                }
            }

            if (poped.empty() || !satisfied)
            {
                return make_pair(Sushi(), false);
            }

            for (size_t i = 0; i < poped.size() - 1; i++)
            {
                queue.push(poped[i]);
            }

            return make_pair(poped.back(), true);
        };

        auto removing = TryPop(used, [&count](auto & sushi) { return count[sushi.t] > 1; });
        if (!removing.second)
        {
            break;
        }

        auto adding = TryPop(remains, [&count](auto & sushi) { return count[sushi.t] == 0; });
        if (!adding.second)
        {
            break;
        }

        ++numKinds;
        sum = sum - removing.first.d + adding.first.d;
        ans = max(ans, sum + numKinds * numKinds);
        used.push(adding.first);
        remains.push(removing.first);
        count[removing.first.t]--;
        count[adding.first.t]++;
    }

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   50 |     sort(S, S + n, [](auto & a, auto & b) { return a.d > b.d; });
      |     ^~~~
      |     short
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k; cin >> n >> k;
  vector<int> ct(n + 1, 0);
  vector<int> ti(n), di(n);
  for(int i = 0; i < n; i++) cin >> ti[i] >> di[i];
  vector<int> od(n);
  iota(od.begin(), od.end());
  sort(od.begin(), od.end(), [&](int a, int b){
    return di[a] > di[b];
  });
  long long ans = 0, diff = 0, sum = 0, ch = 0;
  multiset<int> rem;
  for(int i = 0; i < k; i++) {
    sum += di[od[i]];
    if(ct[ti[od[i]]] == 0) diff++;
    else rem.insert(di[od[i]]);
    ct[ti[od[i]]]++;
  }
  ans = sum + diff * diff;
  for(int i = k + 1; i < n && !rem.empty(); i++){
    if(ct[ti[od[i]]]) continue;
	sum -= *rem.begin(); rem.erase(rem.begin());
    sum += di[od[i]];
    ct[ti[od[i]]]++;
    ans = max(ans, sum + diff * diff);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:7: error: no matching function for call to 'iota(std::vector<int>::iterator, std::vector<int>::iterator)'
    9 |   iota(od.begin(), od.end());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_numeric.h:88:5: note: candidate: 'template<class _ForwardIterator, class _Tp> void std::iota(_ForwardIterator, _ForwardIterator, _Tp)'
   88 |     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
      |     ^~~~
/usr/include/c++/14/bits/stl_numeric.h:88:5: note:   candidate expects 3 arguments, 2 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;

bool num_is_one(int v, vector<int>& used){
    return used[v] == 1;
}

int main(){
    ios::sync_with_stdio(false)
    cin.tie(0);
    int N, K; cin >> N >> K;
    vector<pair<int, int>> dt(N);
    vector<int> used(N+1, 0);
    vector<long long> f(N+1, -1LL);
    for(auto& tmp: dt) cin >> tmp.second >> tmp.first;  // first = d, second = t;

    sort(dt.begin(), dt.end(), greater<pair<int, int>>());

    long long goodness = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    int used_cnt = 0;
    for(int i = 0; i < K; i++){
        que.push(dt[i]);
        goodness += dt[i].first;
        if(used[dt[i].second] == false){
            used_cnt++;
        }
        used[dt[i].second]++;
    }

    f[used_cnt] = goodness;

    for(int i = K; i < N; i++){
        if(used[dt[i].second]) continue;
        while(num_is_one(que.top().second, used)){
            que.pop();
        }
        if(que.empty()){
            break;
        }
        pair<int, int> q = que.top();
        que.pop();
        goodness -= q.first;
        goodness += dt[i].first;
        used[dt[i].second]++;
        used_cnt++;
        f[used_cnt] = goodness;
    }

    long long ans = 0;
    for(int i = 1; i <= N; i++){
        if(f[i] == -1) continue;
        ans = max(ans, f[i] + (long long)i*(long long)i);
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:32: error: expected ';' before 'cin'
    9 |     ios::sync_with_stdio(false)
      |                                ^
      |                                ;
   10 |     cin.tie(0);
      |     ~~~
Language: C

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <cstdio>

#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
typedef long long int ll;
using namespace std;
#define MAX_N 200000
int par[MAX_N];
int dep[MAX_N];

void init(int nu) {
  for(int iu=0;iu<nu;iu++){
    par[iu] = iu;
    dep[iu] = 0;
  }
}
int find(int xu){
  if(par[xu] == xu) return xu;
  return par[xu] = find(par[xu]);
}
void unite(int xu, int yu){
  xu=find(xu);
  yu=find(yu);
  if(xu == yu) return;
  if(dep[xu] < dep[yu]){
    par[xu] = yu;
  }else{
    par[yu] = xu;
    if(dep[xu] == dep[yu]) dep[xu]++;
  }
}
bool same(int xu, int yu){
  return find(xu) == find(yu);
}

int main(int argc, char const *argv[]) {
  //auto c = [](std::pair<int, int> v, std::pair<int, int> v2) { if(v.first > v2.first) return true; else return false; };
  //priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> > > sushi;
  //priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> > > amari;
  priority_queue<int> sushi;
  priority_queue<int, std::vector<int>, std::greater<int> > amari;
  int N, K, spie=0;
  std::cin >> N >> K;
  ll ans=0;
  vvi lis = vv(N, 2, 0, int);
  init(N+2);
  range(i, N) std::cin >> lis[i][1] >> lis[i][0];
  sort(lis.begin(), lis.end());
  reverse(lis.begin(), lis.end());
  range(i, K) {
    ans += lis[i][0];
    if(!same(N+1, lis[i][1])){
      unite(N+1, lis[i][1]);
      spie++;
    }else{
      sushi.push(lis[i][0]);
    }
  }
  ranges(i, K, N){
    if(!same(N+1, lis[i][1])){
      amari.push(lis[i][0]);
    }
  }
  ans = ans + spie*spie;
  ll ma = ans;
  int tem=K;
  while(!sushi.empty() && !amari.empty()){
    if(!same(lis[tem][1], N+1)){
      unite(lis[tem][1], N+1);
      ans = max(ma, ma-sushi.top()+lis[tem][0]+2*spie+1);
      ma = ma-sushi.top()+lis[tem][0]+2*spie+1;
      spie++;
      sushi.pop();
      amari.pop();
    }else{
      amari.pop();
    }
    tem++;
  }
  std::cout << ans << '\n';
  return 0;
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <cstdio>

#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
typedef long long int ll;
using namespace std;
#define MAX_N 2000000
int par[MAX_N];
int dep[MAX_N];

void init(int nu) {
  for(int iu=0;iu<nu;iu++){
    par[iu] = iu;
    dep[iu] = 0;
  }
}
int find(int xu){
  if(par[xu] == xu) return xu;
  return par[xu] = find(par[xu]);
}
void unite(int xu, int yu){
  xu=find(xu);
  yu=find(yu);
  if(xu == yu) return;
  if(dep[xu] < dep[yu]){
    par[xu] = yu;
  }else{
    par[yu] = xu;
    if(dep[xu] == dep[yu]) dep[xu]++;
  }
}
bool same(int xu, int yu){
  return find(xu) == find(yu);
}

int main(int argc, char const *argv[]) {
  //auto c = [](std::pair<int, int> v, std::pair<int, int> v2) { if(v.first > v2.first) return true; else return false; };
  //priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> > > sushi;
  //priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> > > amari;
  priority_queue<int> sushi;
  priority_queue<int, std::vector<int>, std::greater<int> > amari;
  int N, K, spie=0;
  std::cin >> N >> K;
  ll ans=0;
  vvi lis = vv(N, 2, 0, int);
  init(N+2);
  range(i, N) std::cin >> lis[i][1] >> lis[i][0];
  sort(lis.begin(), lis.end());
  reverse(lis.begin(), lis.end());
  range(i, K) {
    ans += lis[i][0];
    if(!same(N+1, lis[i][1])){
      unite(N+1, lis[i][1]);
      spie++;
    }else{
      sushi.push(lis[i][0]);
    }
  }
  ranges(i, K, N){
    if(!same(N, lis[i][1])){
      amari.push(lis[i][0]);
    }
  }
  ans = ans + spie*spie;
  ll ma = ans;
  int tem=K;
  while(!sushi.empty() && !amari.empty()){
    if(!same(lis[tem][1], N+1)){
      unite(lis[tem][1], N+1);
      ans = max(ma, ma-sushi.top()+lis[tem][0]+2*spie+1);
      ma = ma-sushi.top()+lis[tem][0]+2*spie+1;
      spie++;
      sushi.pop();
      amari.pop();
    }else{
      amari.pop();
    }
    tem++;
  }
  std::cout << ans << '\n';
  return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:56:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   56 |   sort(lis.begin(), lis.end());
      |   ^~~~
      |   short
a.cc:57:3: error: 'reverse' was not declared in this scope
   57 |   reverse(lis.begin(), lis.end());
      |   ^~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

ll solve(int N, int K, vi& t, vi& d){
  map<int, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  vi winner, looser;
  for (auto sushi_list: p){
    vi q=p.second;
    sort(q.begin(), q.end());
    int w=q.back();
    winner.push_back(w);
    q.pop_back();
    looser.insert(looser.begin(), q.begin(), q.end());
  }

  sort(winner.begin(), winner.end(), greater<int>());
  sort(looser.begin(), looser.end(), greater<int>());

  int W=winner.size();
  int L=looser.size();

  vl winner_cumsum(W+1);
  vl looser_cumsum(L+1);
  winner_cumsum[0]=0;
  looser_cumsum[0]=0;

  for (int i=0;i<W;++i){
    winner_cumsum[i+1]=winner_cumsum[i]+winner[i];
  }

  for (int i=0;i<L;++i){
    looser_cumsum[i+1]=looser_cumsum[i]+looser[i];
  }

  ll best=0;

  for (int n_unique=1;n_unique<=W;++n_unique){
    if(n_unique<=K&&(K-n_unique<=L)){
      ll tmp=winner_cumsum[n_unique]+looser[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }

  return best;
}

int main(){
  int N, K;cin>>N>>K;
  vi t, d;
  for (int i=0;i<N;i++){
    int t_, d_;cin>>t_>>d_;
    t.push_back(t_);
    d.push_back(d_);
  }

  ll ans=solve(N, K, t, d);
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:15:25: error: 'p' was not declared in this scope
   15 |   for (auto sushi_list: p){
      |                         ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
struct p{
    int v;
    int type;
}a[maxn];
bool operator<(p a,p b){
    return a.v>b.v;
}
int vis[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i].type>>a[i].v;
    }
    sort(a,a+n);
    stack<p>q;
    long long cnt=0;
    long long ans=0;
    for(int i=0;i<k;i++){
        if(!vis[a[i].type]){
            cnt++;
            vis[a[i].type]=1;
        }
        else 
            q.push(s[i]);
        ans+=a[i].v;
    }
    long long out=ans+cnt*cnt;
    for(int i=k;i<n;i++){
        if(vis[a[i].type])continue;
        if(q.empty())break;
        cnt++;
        ans+=a[i].v-q.top().v;
        out=max(out,ans+cnt*cnt)
        vis[a[i].type]++;
        q.pop();
        //q.push(a[i]);
    }
    cout<<out;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:20: error: 's' was not declared in this scope
   29 |             q.push(s[i]);
      |                    ^
a.cc:38:33: error: expected ';' before 'vis'
   38 |         out=max(out,ans+cnt*cnt)
      |                                 ^
      |                                 ;
   39 |         vis[a[i].type]++;
      |         ~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

ll solve(int N, int K, vi& t, vi& d){
  map<int, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  vi head, tail;
  for(auto p:sushi_list){
    sort(p.second.begin(), p.second.end());
    head.push_back(p.second.back());

    p.second.pop_back();

    tail.insert(tail.end(), p.second.begin(), p.second.end());
  }

  sort(head.begin(), head.end(), greater<int>());
  sort(tail.begin(), tail.end(), greater<int>());

  int H=head.size();
  int T=tail.size();
  vl head_cum(H+1);
  vl tail_cum(T+1);

  head_cum[0]=0;
  tail_cum[0]=0;

  for (int i=1;i<H+1;i++){
    head_cum[i]=head_cum[i-1]+head[i-1];
  }
  for (int i=1;i<T+1;i++){
    tail_cum[i]=tail_cum[i-1]+tail[i-1];
  }

  ll best=0;
  for (int n_unique=1;n_unique<=H;n_unique++){
    if(n_unique<=K&&K-n_unique<=T){
      ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }
  return best;
}

int main(){
  int N, K;cin>>N>>K;
  vi t, d;
  for (int i=0;i<N;i++){
    int t_, d_;cin>>t_>>d_;
    t.push_back(t_);
    d.push_bak(d_);
  }
  cout<< solve(N, K, t, d);
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:7: error: 'vi' {aka 'class std::vector<int>'} has no member named 'push_bak'; did you mean 'push_back'?
   57 |     d.push_bak(d_);
      |       ^~~~~~~~
      |       push_back
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

ll solve(int N, int K, vi& t, vi& d){
  map<int, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  vi head, tail;
  for(int i=0;i<N;i++){
    vi p=sushi_list[t[i]].second;
    sort(p.begin(), p.end());
    head.push_back(p.back());

    p.pop_back();

    tail.insert(tail.end(), p.begin(), p.end());
  }

  sort(head.begin(), head.end(), greater<int>());
  sort(tail.begin(), tail.end(), greater<int>());

  int H=head.size();
  int T=tail.size();
  vl head_cum(H+1);
  vl tail_cum(T+1);

  head_cum[0]=0;
  tail_cum[0]=0;

  for (int i=1;i<H+1;i++){
    head_cum[i]=head_cum[i-1]+head[i-1];
  }
  for (int i=1;i<T+1;i++){
    tail_cum[i]=tail_cum[i-1]+tail[i-1];
  }

  ll best=0;
  for (int n_unique=1;n_unique<=H;n_unique++){
    if(n_unique<=K&&K-n_unique<=T){
      ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }
  return best;
}

int main(){
  int N, K;cin>>N>>K;
  vi t, d;
  for (int i=0;i<N;i++){
    int t_, d_;cin>>t_>>d_;
    t.push_back(t_);
    d.push_bak(d_);
  }
  cout<< solve(N, K, t, d);
  return 0;
}


Compiler output:
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:15:27: error: 'std::map<int, std::vector<int> >::mapped_type' {aka 'class std::vector<int>'} has no member named 'second'
   15 |     vi p=sushi_list[t[i]].second;
      |                           ^~~~~~
a.cc: In function 'int main()':
a.cc:58:7: error: 'vi' {aka 'class std::vector<int>'} has no member named 'push_bak'; did you mean 'push_back'?
   58 |     d.push_bak(d_);
      |       ^~~~~~~~
      |       push_back
Language: C++

//必要なパッケージを一括ロード
#include <bits/stdc++.h>
using namespace std;

 //typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;



 //お？vector は&で受け取るん？
ll solve(int N, int K, vi& t, vi& d) {
  //stat は、各種類に対して、美味しさの一覧を与えるベクトルが対応している。
    map<int,vi> stat;
    for (int i=0;i<N;i++){
        stat[t[i]].push_back(d[i]);
    }
    vi head, tail;
    //型を自動で推論できる。
    //map の入っているやつ全てを舐めるループ
    //p.first が key, p.secondがcount(ここではベクトルになっている)
    for (auto p: stat) {
      //map で、p.secondはcountの方
        sort(p.second.begin(), p.second.end());
        //vector.back()は、vector の末尾への参照を返す
        //headには、p.secondの最大限を
        head.push_back(p.second.back());
        //末尾要素をきる
        p.second.pop_back();
        //tailのけつの後ろに、p.secondを繋げる。
        tail.insert(tail.end(), p.second.begin(), p.second.end());
    }

    //ソートする。
    sort(head.begin(), head.end(), greater<int>());
    sort(tail.begin(), tail.end(), greater<int>());
    //H,Tでheadとtailのサイズ
    int H = head.size(), T = tail.size();

    //head_accは、headの累積和 tail_accもそう。
    //vector(size)
    vll head_acc(H+1), tail_acc(T+1);
    head_acc[0] = tail_acc[0] = 0;
    for (int i=0;i<H;i++) head_acc[i+1] = head_acc[i] + head[i];
    for (int i=0;i<T;i++) tail_acc[i+1] = tail_acc[i] + tail[i];

    //ん？tailの長さって、Nじゃないの？あ、ちゃう。N-head数
    //best score
    ll best = 0;
    //
    for (int kinds=1; kinds<=T; ++kinds) {
      //種類数<=K&&K<=種類すう＋tailの長さ
        if ((0<=K-kinds)&&(K-kinds<=H)) {
          　//上位から拾っていく あ！kind種類は、最大限。それ以外は、大きい方から順に？だね？
            ll score = (head_acc[kinds] + tail_acc[K-kinds]) + (ll)kinds*kinds;
            best = max(best, score);
        }
    }
    return best;
}

int main() {
    int N, K; scanf("%d%d", &N,&K);
    vi t(N), d(N);
    for (int i=0;i<N;i++) scanf("%d%d", &t[i],&d[i]);
    cout << solve(N,K,t,d) << endl;
    return 0;
}


Compiler output:
a.cc:55:11: error: extended character 　 is not valid in an identifier
   55 |           　//上位から拾っていく あ！kind種類は、最大限。それ以外は、大きい方から順に？だね？
      |           ^
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:55:11: error: '\U00003000' was not declared in this scope
   55 |           　//上位から拾っていく あ！kind種類は、最大限。それ以外は、大きい方から順に？だね？
      |           ^~
a.cc:57:30: error: 'score' was not declared in this scope
   57 |             best = max(best, score);
      |                              ^~~~~
Language: C++

//必要なパッケージを一括ロード
#include <bits/stdc++.h>
using namespace std;

 //typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;



 //お？vector は&で受け取るん？
ll solve(int N, int K, vi& t, vi& d) {
  //stat は、各種類に対して、美味しさの一覧を与えるベクトルが対応している。
    map<int,vi> stat;
    for (int i=0;i<N;i++){
        stat[t[i]].push_back(d[i]);
    }
    vi head, tail;
    //型を自動で推論できる。
    //map の入っているやつ全てを舐めるループ
    //p.first が key, p.secondがcount(ここではベクトルになっている)
    for (auto p: stat) {
      //map で、p.secondはcountの方
        sort(p.second.begin(), p.second.end());
        //vector.back()は、vector の末尾への参照を返す
        //headには、p.secondの最大限を
        head.push_back(p.second.back());
        //末尾要素をきる
        p.second.pop_back();
        //tailのけつの後ろに、p.secondを繋げる。
        tail.insert(tail.end(), p.second.begin(), p.second.end());
    }

    //ソートする。
    sort(head.begin(), head.end(), greater<int>());
    sort(tail.begin(), tail.end(), greater<int>());
    //H,Tでheadとtailのサイズ
    int H = head.size(), T = tail.size();

    //head_accは、headの累積和 tail_accもそう。
    //vector(size)
    vll head_acc(H+1), tail_acc(T+1);
    head_acc[0] = tail_acc[0] = 0;
    for (int i=0;i<H;i++) head_acc[i+1] = head_acc[i] + head[i];
    for (int i=0;i<T;i++) tail_acc[i+1] = tail_acc[i] + tail[i];

    //ん？tailの長さって、Nじゃないの？あ、ちゃう。N-head数
    //best score
    ll best = 0;
    //
    for (int kinds=1; kinds<=H; ++kinds) {
      //種類数<=K&&K<=種類すう＋tailの長さ
        if ((0<=K-kinds)&&(K-kinds<=T)) {
          　//上位から拾っていく あ！kind種類は、最大限。それ以外は、大きい方から順に？だね？
            ll score = (head_acc[kinds] + tail_acc[K-kinds]) + (ll)kinds*kinds;
            best = max(best, score);
        }
    }
    return best;
}

int main() {
    int N, K; scanf("%d%d", &N,&K);
    vi t(N), d(N);
    for (int i=0;i<N;i++) scanf("%d%d", &t[i],&d[i]);
    cout << solve(N,K,t,d) << endl;
    return 0;
}


Compiler output:
a.cc:55:11: error: extended character 　 is not valid in an identifier
   55 |           　//上位から拾っていく あ！kind種類は、最大限。それ以外は、大きい方から順に？だね？
      |           ^
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:55:11: error: '\U00003000' was not declared in this scope
   55 |           　//上位から拾っていく あ！kind種類は、最大限。それ以外は、大きい方から順に？だね？
      |           ^~
a.cc:57:30: error: 'score' was not declared in this scope
   57 |             best = max(best, score);
      |                              ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ll> vll;


ll solve(int N, int K, vi& t, vi& d){
  //sushi_listを作る.各tiに対して、その美味しさリストを対応させる。
  map<int, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  //各種類の美味しさmaxの奴ら（head)と、それ以外(tail)に分ける。
  vi head, tail;
  for (auto p: sushi_list){
    vi q=p.second;
    sort(q.begin(), q.end());
    head.push_back(q.back());
    q.pop_back();
    tail.insert(tail.end(), q.begin(),q.end());
  }

  //head, tailの累積和を計算
  int H=head.size();
  int T=tail.size();
  vector<ll> head_cum(H+1);
  vector<ll> tail_cum(T+1);
  head_cum[0]=0;
  tail_cum[0]=0;
  for (int i=0;i<H;i++){
    head_cum[i+1]=head_cum[i]+head[i+1];
  }
  for (int i=0;i<T;i++){
    tail_cum[i+1]=tail_cum[i]+tail[i+1]
  }

  //ansを計算
  ll best=0;
  for (int n_unique=1;n_unique<=T;n_unique++){
    if((n_unique<=K)&&(K-n_unique<=H)){
      ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }
  return best;
}

int main(){
  int N, K;scanf("%d%d", &N, &K);
  vi t(N), d(N);
  for (int i=0;i<N;i++){
    scanf("%d%d", &t[i], &d[i]);
    cout << solve(N, K, t, d);
    return 0;
  }
}


Compiler output:
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:38:40: error: expected ';' before '}' token
   38 |     tail_cum[i+1]=tail_cum[i]+tail[i+1]
      |                                        ^
      |                                        ;
   39 |   }
      |   ~
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ll> vll;


ll solve(int N, int K, vi& t, vi& d){
  //sushi_listを作る.各tiに対して、その美味しさリストを対応させる。
  map<int, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  //各種類の美味しさmaxの奴ら（head)と、それ以外(tail)に分ける。
  vi head, tail;
  for (auto p: sushi_list){
    vi q=p.second;
    sort(q.begin(), q.end());
    head.push_back(q.back());
    q.pop_back();
    tail.insert(tail.end(), q.begin(),q.end());
  }

  //head, tailの累積和を計算
  int H=head.size();
  int T=tail.size();
  ll head_cum(H+1);
  ll tail_cum(T+1);
  head_cum[0]=0;
  tail_cum[0]=0;
  for (int i=0;i<H;i++){
    head_cum[i+1]=head_cum[i]+head[i+1];
  }
  for (int i=0;i<T;i++){
    tail_cum[i+1]=tail_cum[i]+tail[i+1]
  }

  //ansを計算
  ll best=0;
  for (int n_unique=1;n_unique<=T;n_unique++){
    if((n_unique<=K)&&(K-n_unique<=H)){
      ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }
  return best;
}

int main(){
  int N, K;scanf("%d%d", &N, &K);
  vi t(N), d(N);
  for (int i=0;i<N;i++){
    scanf("%d%d", &t[i], &d[i]);
    cout << solve(N, K, t, d);
    return 0;
  }
}


Compiler output:
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:32:11: error: invalid types 'll {aka long long int}[int]' for array subscript
   32 |   head_cum[0]=0;
      |           ^
a.cc:33:11: error: invalid types 'll {aka long long int}[int]' for array subscript
   33 |   tail_cum[0]=0;
      |           ^
a.cc:35:13: error: invalid types 'll {aka long long int}[int]' for array subscript
   35 |     head_cum[i+1]=head_cum[i]+head[i+1];
      |             ^
a.cc:35:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   35 |     head_cum[i+1]=head_cum[i]+head[i+1];
      |                           ^
a.cc:38:13: error: invalid types 'll {aka long long int}[int]' for array subscript
   38 |     tail_cum[i+1]=tail_cum[i]+tail[i+1]
      |             ^
a.cc:38:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   38 |     tail_cum[i+1]=tail_cum[i]+tail[i+1]
      |                           ^
a.cc:45:22: error: invalid types 'll {aka long long int}[int]' for array subscript
   45 |       ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      |                      ^
a.cc:45:41: error: invalid types 'll {aka long long int}[int]' for array subscript
   45 |       ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      |                                         ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;


ll solve(int N, int K, vi& t, vi& d){
  map<int, vi> sushi_list;
  for (int n=0;n<N;n++){
    sushi_list[t[i]].push_back(d[i]);
  }

  vi head, tail;

  for (auto p: sushi_list){
    vi q=p.second;
    sort(q.begin(), q.end());
    head.push_back(q.back());
    q.pop_back();
    tail.insert(tail.end(), q.begin(), q.end());
  }

  int T=tail.size();
  int H=head.size();
  vector<ll> tail_acc(T+1);
  vector<ll> head_acc(H+1);
  tail_acc[0]=0;
  head_acc[0]=0;
  for (int i=1;i<T+1;i++){
    tail_acc[i]=tail_acc[i-1]+tail[i];
  }
  for (int i=1;i<H+1;i++){
    head_acc[i]=head_acc[i-1]+head[i];
  }

  ll best_score=0;
  for (int num_unique=1;num_unique<K+1;num_unique++){
    if ((num_unique<=K)&&(K-num_unique<=H)){
      ll a=head_acc[num_unique]+tail_acc[K-num_unique]+(ll)num_unique*num_unique;
      best_score=max(best_score, a);
    }
  }
  return best_score;
}

int main(){
  int N, K; scanf("%d%d", &N,&K);
  vi t(N), d(N);
  for (int i=0;i<N;i++) scanf("%d%d", &t[i],&d[i]);
  cout << solve(N,K,t,d) << endl;
  return 0;
}

Compiler output:
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:11:18: error: 'i' was not declared in this scope
   11 |     sushi_list[t[i]].push_back(d[i]);
      |                  ^
Language: C++

#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

typedef tuple<ll, ll> sushi;
//貪欲法 Greedy

ll main() {
  ll N, K;
  cin >> N >> K;
  vector<sushi> V(N);

  for (ll i = 0; i < N; i++) {
    ll t, d;
    cin >> t >> d;
    t--;
    V[i] = sushi(d, t);  // tupleの代入の仕方はこれ dtの順番に注意。
  }

  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());  //降順ソート

  vector<ll> cnt(N + 1, 0);  // 1-indexed
  priority_queue<sushi, vector<sushi>, greater<sushi>> PQ;
  // priority_queueで昇順にするにはこう

  ll ans = 0;
  ll tmpans = 0;

  for (ll i = 0; i < K; i++) {
    ll val = get<0>(V[i]);  // tupleの要素取得はこれ 0-indexed
    ll kind = get<1>(V[i]);
    tmpans += val;
    cnt[kind]++;
    PQ.push(V[i]);
  }

  ll count_num = 0;  //何種類の寿司を使ったか
  for (ll i = 0; i < N; i++) {
    if (cnt[i] > 0) count_num++;
  }

  ans += tmpans + count_num * count_num;

  for (ll i = K; i < N; i++) {
    ll val = get<0>(V[i]);
    ll kind = get<1>(V[i]);

    if (cnt[kind] > 0) continue;  //種類count_numが増えるかどうか判定

    while (!PQ.empty()) {
      ll qval = get<0>(PQ.top());
      ll qkind = get<1>(PQ.top());
      PQ.pop();

      if (cnt[qkind] == 1) continue;
      //入れ替えると結局種類数が減るので何もしない
      //一つしかないので次回から考慮する必要がないのでpushしない

      cnt[qkind]--;
      tmpans -= qval;
      cnt[kind]++;
      tmpans += val;
      count_num++;
      ans = max(ans, tmpans + count_num * count_num);

      break;
    }
  }

  cout << ans << endl;
}



Compiler output:
a.cc:13:1: error: '::main' must return 'int'
   13 | ll main() {
      | ^~
Language: C++

#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long

int main(void)
{
  int n, k;
  cin >> n >> k;
  vec<pair<ll, ll>> s(n);
  rep(i, n) cin >> s[i].second >> s[i].first;
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());

  ll m = 0;
  vec<ll> dp(n, 0);
  ll p = 0;
  rep(i, k) {
    m += s[i].first;
    if (!dp[s[i].second]) p++;
    dp[s[i].second]++;
  }

  m += p * p;
  ll prev = m;
  //大きい順に追加、違う種類を入れる
  int cur = k;
  //小さい順に削除、種類が減らないやつを消す
  int rm = k - 1;

  for (int i = 1; p + i <= k; i++) {
    ll p_ = p + (ll)i;
    //１個以上あるやつを探す
    while(rm >= 0 && dp[s[rm].second] <= 1) rm--;
    if (rm < 0) break;
    ll temp = prev - s[rm].first + 2 * p_ - 1;
    dp[s[rm].second]--;
    rm--;
    //まだ含まれてないやつを探す
    while(cur < n && dp[s[cur].second]) cur++;
    if (cur => n) break;
    temp += s[cur].first;
    dp[s[cur].second]++;
    cur++;

    if (temp > m) {
      m = temp;
    }
    prev = temp;
  }
  cout << m << endl;
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:17:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   17 |   sort(s.begin(), s.end());
      |   ^~~~
      |   short
a.cc:18:3: error: 'reverse' was not declared in this scope
   18 |   reverse(s.begin(), s.end());
      |   ^~~~~~~
a.cc:46:14: error: expected primary-expression before '>' token
   46 |     if (cur => n) break;
      |              ^
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
typedef long long ll;
using namespace std;


int main(){
  //入力の受け取り
  int N, K;cin>>N>>K;
  //設定
  vector <pair<ll, int> > sushi_list;
  for (int n=0;n<N;n++){
    int t; cin>>t;
    ll d;cin>> d;
    pair<ll, int> p=make_pair(d, t);
    sushi_list.push_back(p);
  }

  //sushi_listを、美味しい順にソート
  sort(sushi_list.begin(), sushi_list.end(), greater<pair<ll, int> >() );

  //初期値を設定
  //スコア
  ll raw_score=0;
  //選んだ寿司の種類数
  ll num_unique=0;
  //選ばれた寿司のリストと、その個数
  map<int, int> used;
  //全て0に初期化しておく。
  for (int t=0;t<N;t++){
    used[t]=0;
  }
  //まず、個数を無視して美味しい順にk個を選択。
  for (int k=0;k<K;k++){
    ll d=sushi_list[k].first;
    int t=sushi_list[k].second;
    //スコアに美味しさをたす。
    raw_score+=d;
    //リストを更新
    used[t]++;
    //種類tがここで出て来たのしかなければ,
    if (used[t]==1){
      //種類すうを一つ増やす。
      num_unique++;
    }
  }

  //スコア
  vector< pair<int, ll> > ans_list;
  pair<int, ll> p=make_pair(raw_score, num_unique);
  ans_list.push_back(p);

  int position=K-1;
  int app=0;
  int rem=0;
  for (int k=K;k<N;k++){
    pair<ll, int> p=sushi_list[k];
    ll d=p.first;
    int t=p.second;
    if(used[t]==0){
      used_unique++;
      app+=d;
      used[t]++;
      while(used[sushi_list[position].second]<=1){
        position--;
      }
      pair<ll, int> q=sushi_list[position];
      ll d_=q.first;
      int t_=q.second;
      rem+=d_;
      used[t_]--;

      pair<int, ll> p=make_pair(used_unique, raw_score+add-rem);
      ans_list.push_back(p);
    }

    ll ans=0;
    int M=ans_list.size();
    for (int m=0;m<M;m++){
      int used=ans_list[m].first;
      ll raw_score=ans_list[m].second;
      ans=max(ans, raw_score+used*used);
    }
    cout << ans;
    return 0;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:63:7: error: 'used_unique' was not declared in this scope
   63 |       used_unique++;
      |       ^~~~~~~~~~~
a.cc:75:56: error: 'add' was not declared in this scope
   75 |       pair<int, ll> p=make_pair(used_unique, raw_score+add-rem);
      |                                                        ^~~
a.cc:88:4: error: expected '}' at end of input
   88 |   }
      |    ^
a.cc:9:11: note: to match this '{'
    9 | int main(){
      |           ^