Language: C++

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()

struct data{ll d; ll t;};

ll max(ll a, ll b){
    if (a > b) return a;
    else return b;
}

int main(){
    ll N,K;
    scanf("%lld%lld",&N,&K);
    priority_queue<data> Q;
    priority_queue<data> q;
    ll ctl[100010] = {0};
    ll Max = 0;
    rep(i,N){
        data temp;
        scanf("%lld%lld",&temp.d,&temp.t);
        Q.push(temp);
        if (temp.t >= Max) Max = temp.t;
    }
    ll start= 0;
    ll sum = 0;
    vector <ll> basicpoint;
    rep(i,K){
        data temp = Q.top();
        Q.pop();
        sum += temp.d;
        if (ctl[temp.t] == 0) start ++;
        ctl[temp.t]++;
        data in;
        in.d = -temp.d; in.t = temp.t;
        q.push(in);
    }
    basicpoint.push_back(sum);
    while(1){
        ll breakcheck = 0;
        vector <data> remainq;
        vector <data> remainQ;
        data send;
        data accept;
        while(1){
            data temp = Q.top();
            if (ctl[temp.t] == 0){
                accept.d = -temp.d;
                accept.t = temp.t;
                ctl[temp.t] ++;
                sum += temp.d;
                Q.pop();
                break;
            }
            else{
                remainQ.push_back(temp);
                Q.pop();
            }
            ll ppp = Q.size();
            if (ppp == 0){
                breakcheck = 1;
                break;
            }
        }
        while(1){
            data temp = q.top();
            if (ctl[temp.t] >= 2){
                send.d = -temp.d;
                send.t = temp.t;
                ctl[temp.t]--;
                sum -= -temp.d;
                q.pop();
                break;
            }
            else{
                remainq.push_back(temp);
                q.pop();
            }
            ll qqq = q.size();
            if (qqq == 0){
                breakcheck = 1;
                break;
            }
        }
        if (breakcheck == 1) break;
        ll sizeq,sizeQ;
        sizeq = remainq.size(); sizeQ = remainQ.size();
        rep(i,sizeq) q.push(remainq[i]);
        q.push(accept);
        rep(i,sizeQ) Q.push(remainQ[i]);
        Q.push(send);
        basicpoint.push_back(sum);
    }
    ll ans = 0;
    ll size = basicpoint.size();
    rep(i,size){
        ll temp = basicpoint[i] + pow(start+i,2);
        ans = max(ans,temp);
    }
    cout << ans << endl;
    return 0;
}






Compiler output:
a.cc: In function 'int main()':
a.cc:28:24: error: template argument 1 is invalid
   28 |     priority_queue<data> Q;
      |                        ^
a.cc:28:24: error: template argument 2 is invalid
a.cc:28:24: error: template argument 3 is invalid
a.cc:29:24: error: template argument 1 is invalid
   29 |     priority_queue<data> q;
      |                        ^
a.cc:29:24: error: template argument 2 is invalid
a.cc:29:24: error: template argument 3 is invalid
a.cc:33:9: error: reference to 'data' is ambiguous
   33 |         data temp;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:18:8: note:                 'struct data'
   18 | struct data{ll d; ll t;};
      |        ^~~~
a.cc:34:27: error: 'temp' was not declared in this scope; did you mean 'tm'?
   34 |         scanf("%lld%lld",&temp.d,&temp.t);
      |                           ^~~~
      |                           tm
a.cc:35:11: error: request for member 'push' in 'Q', which is of non-class type 'int'
   35 |         Q.push(temp);
      |           ^~~~
a.cc:42:9: error: reference to 'data' is ambiguous
   42 |         data temp = Q.top();
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:18:8: note:                 'struct data'
   18 | struct data{ll d; ll t;};
      |        ^~~~
a.cc:43:11: error: request for member 'pop' in 'Q', which is of non-class type 'int'
   43 |         Q.pop();
      |           ^~~
a.cc:44:16: error: 'temp' was not declared in this scope; did you mean 'tm'?
   44 |         sum += temp.d;
      |                ^~~~
      |                tm
a.cc:47:9: error: reference to 'data' is ambiguous
   47 |         data in;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:18:8: note:                 'struct data'
   18 | struct data{ll d; ll t;};
      |        ^~~~
a.cc:48:9: error: 'in' was not declared in this scope; did you mean 'i'?
   48 |         in.d = -temp.d; in.t = temp.t;
      |         ^~
      |         i
a.cc:49:11: error: request for member 'push' in 'q', which is of non-class type 'int'
   49 |         q.push(in);
      |           ^~~~
a.cc:54:21: error: template argument 1 is invalid
   54 |         vector <data> remainq;
      |                     ^
a.cc:54:21: error: template argument 2 is invalid
a.cc:55:21: error: template argument 1 is invalid
   55 |         vector <data> remainQ;
      |                     ^
a.cc:55:21: error: template argument 2 is invalid
a.cc:56:9: error: reference to 'data' is ambiguous
   56 |         data send;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:18:8: note:                 'struct data'
   18 | struct data{ll d; ll t;};
      |        ^~~~
a.cc:57:9: error: reference to 'data' is ambiguous
   57 |         data accept;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:18:8: note:                 'struct data'
   18 | struct data{ll d; ll t;};
      |        ^~~~
a.cc:59:13: error: reference to 'data' is ambiguous
   59 |             data temp = Q.top();
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:18:8: note:                 'struct data'
   18 | struct data{ll d; ll t;};
      |        ^~~~
a.cc:60:21: error: 'temp' was not declared in this scope; did you mean 'tm'?
   60 |             if (ctl[temp.t] == 0){
      |                     ^~~~
      |                     tm
a.cc:61:17: error: 'accept' was not declared in this scope
   61 |                 accept.d = -temp.d;
      |                 ^~~~~~
a.cc:65:19: error: request for member 'pop' in 'Q', which is of non-class type 'int'
   65 |                 Q.pop();
      |                   ^~~
a.cc:69:25: error: request for member 'push_back' in 'remainQ', which is of non-class type 'int'
   69 |                 remainQ.push_back(temp);
      |                         ^~~~~~~~~
a.cc:70:19: error: request for member 'pop' in 'Q', which is of non-class type 'int'
   70 |                 Q.pop();
      |                   ^~~
a.cc:72:24: error: request for member 'size' in 'Q', which is of non-class type 'int'
   72 |             ll ppp = Q.size();
      |                        ^~~~
a.cc:79:13: error: reference to 'data' is ambiguous
   79 |             data temp = q.top();
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/i