Language: C++

#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= (j);i--)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

int N,K;
const int maxn = 1e5+5;

vector<LL> ts[maxn];
set<int> tt;
vector<int> select;

struct Cmp{
    bool operator()(const int a,const int b) const{
        return ts[a][0] > ts[b][0];
    }
};

int main()
{
    scanf("%d %d",&N,&K);
    _for(i,0,N){
        LL d;
        int t;
        scanf("%d %lld",&t,&d);
        ts[t].push_back(d);
        tt.insert(t);
    }

    for(auto a:tt){
        sort(ALL(ts[a]),greater<LL>());
        select.push_back(a);
    }

    sort(ALL(select),Cmp());
    priority_queue<LL,vector<LL>,greater<LL>> pq;
    LL ans = 0;
    LL temp = 0;

    _for(i,0,select.size()){
        LL genere = i+1;
        int s = select[i];
        temp += ts[s][0];
        temp -= (genere-1)*(genere-1);
        temp += genere*genere;

        if(pq.size() > K-genere){
            LL dele = pq.top();
            // << dele << endl;
            pq.pop();
            temp -= dele;
        }

        if(i == K-1){
            //cout << temp << endl;
            ans = max(ans,temp);
            break;
        }

        _for(j,1,ts[s].size()){
            LL ne = ts[s][j];
            if(pq.size() < K-genere){
                temp += ne;
                pq.push(ne);
            }
            else{
                if(ne <= pq.top()) break;
                temp -= pq.top();
                temp += ne;
                pq.pop();
                pq.push(ne);
            }
        }

        //cout << temp << endl;

        ans = max(ans,temp);
    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:29:13: error: 'std::vector<int> select' redeclared as different kind of entity
   29 | vector<int> select;
      |             ^~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:514,
                 from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/sys/select.h:102:12: note: previous declaration 'int select(int, fd_set*, fd_set*, fd_set*, timeval*)'
  102 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
a.cc: In function 'int main()':
a.cc:50:16: error: request for member 'push_back' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
   50 |         select.push_back(a);
      |                ^~~~~~~~~
a.cc:7:18: error: request for member 'begin' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
    7 | #define ALL(x) x.begin(),x.end()
      |                  ^~~~~
a.cc:53:10: note: in expansion of macro 'ALL'
   53 |     sort(ALL(select),Cmp());
      |          ^~~
a.cc:7:28: error: request for member 'end' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
    7 | #define ALL(x) x.begin(),x.end()
      |                            ^~~
a.cc:53:10: note: in expansion of macro 'ALL'
   53 |     sort(ALL(select),Cmp());
      |          ^~~
a.cc:58:21: error: request for member 'size' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
   58 |     _for(i,0,select.size()){
      |                     ^~~~
a.cc:4:42: note: in definition of macro '_for'
    4 | #define _for(i,j,N) for(int i = (j);i < (N);i++)
      |                                          ^
a.cc:60:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |         int s = select[i];
      |                         ^
a.cc:60:25: error: invalid conversion from 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to 'int' [-fpermissive]
   60 |         int s = select[i];
      |                         ^
      |                         |
      |                         int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)