이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
typedef pair<int, int> ii;
const int N = 2e3 + 5;
const int inf = 1e14;
int n, dp[N][N];
ii a[N];
signed main() {
    cin.tie(0), ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i].fi >> a[i].se;
    sort(a + 1, a + 1 + n);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++)
            dp[i][j] = -inf;
    }
    dp[0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= n; j++) {
            if(dp[i][j] == -inf) continue;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if(a[i + 1].fi == 0)
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a[i + 1].se);
            if(a[i + 1].fi)
                dp[i + 1][max(j - a[i + 1].fi + 1, 1ll)] = max(dp[i + 1][max(j - a[i + 1].fi + 1, 1ll)], dp[i][j] + a[i + 1].se);
        }
    }
    cout << max(dp[n][1], 0ll);
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |