Language: C++

#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, K, t, d, s;
ll res[100001], S, RES;
set<int>st;
priority_queue<iP>q;



int main() {
	cin >> N >> K;
	for (int i = 0; i != N; ++i) {
		cin >> t >> d;
		st.insert(t);
		q.push(mkp(d, t));
	}
	s = st.size();
	st.clear();
	for (int i = 0; i != K; ++i) {
		res[K - i - 1] = res[K - i] + q.top().first;
		st.insert(q.top().second);
		q.pop();
	}
	for (int i = s - 1; i != -1; --i)
		res[i] = res[max(i - st.size() + 1, unsigned(0))];
	while (!q.empty()) {
		if (st.find(q.top().second) == st.end()) {
			st.insert(q.top().second);
			S += q.top().first;
			res[st.size() - 1] += S;
		}
		q.pop();
	}
	for (ll i = 0; i != s; ++i) {
		RES = max(RES, res[i] + (i + 1)*(i + 1));
	}
	cout << RES << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:33: error: no matching function for call to 'max(std::set<int>::size_type, unsigned int)'
   35 |                 res[i] = res[max(i - st.size() + 1, unsigned(0))];
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:35:33: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'unsigned int')
   35 |                 res[i] = res[max(i - st.size() + 1, unsigned(0))];
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:35:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   35 |                 res[i] = res[max(i - st.size() + 1, unsigned(0))];
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~