Language: C++

#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

int f(int i) {
    return i * 2;
}

void solve() {
    int N, K;
    cin >> N >> K;
    vector<pll> B(N);
    for (int i = 0; i < N; i++) {
        ll s, k;
        cin >> s >> k;
        k--;
        B[i] = {k, s};
    }
    sort(all(B), [](pll a, pll b){
        if (a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    });

    vector<int> offset(10, -1);
    for (int i = 0; i < N; i++) {
        if (offset[B[i].first] == -1) offset[B[i].first] = i;
    }

    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(K + 1, vector<int>(2, -1)));

    dp[0][0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= K; j++) {
            if (j + 1 <= K && dp[i][j][0] != -1) {
                chmax(dp[i + 1][j + 1][0], dp[i][j][0] + B[i].second + f(i - offset[B[i].first]));
            }
            
            // 切り替わるタイミングで0, そうでないとき1
            int nextf = 1 - ((i == N - 1) || ((i < N - 1) && B[i].first != B[i + 1].first));
            if (dp[i][j][0] != -1) chmax(dp[i + 1][j][nextf], dp[i][j][0]);
            if (dp[i][j][1] != -1) chmax(dp[i + 1][j][nextf], dp[i][j][1]);
        }
    }

    cout << max(dp[N][K][0], dp[N][K][1]) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:7:30: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, long long int)'
    7 | #define chmax(x, y) (x) = max((x), (y))
      |                           ~~~^~~~~~~~~~
a.cc:46:17: note: in expansion of macro 'chmax'
   46 |                 chmax(dp[i + 1][j + 1][0], dp[i][j][0] + B[i].second + f(i - offset[B[i].first]));
      |                 ^~~~~
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:7:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
    7 | #define chmax(x, y) (x) = max((x), (y))
      |                           ~~~^~~~~~~~~~
a.cc:46:17: note: in expansion of macro 'chmax'
   46 |                 chmax(dp[i + 1][j + 1][0], dp[i][j][0] + B[i].second + f(i - offset[B[i].first]));
      |                 ^~~~~
/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:7:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
    7 | #define chmax(x, y) (x) = max((x), (y))
      |                           ~~~^~~~~~~~~~
a.cc:46:17: note: in expansion of macro 'chmax'
   46 |                 chmax(dp[i + 1][j + 1][0], dp[i][j][0] + B[i].second + f(i - offset[B[i].first]));
      |                 ^~~~~