This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e3 + 5;
const long long inf = 1e18;
int n;
long long dp[N][N];
array<int, 2> a[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i][0] >> a[i][1];
}
sort(a + 1, a + n + 1, [&](const auto &a, const auto &b) {
return a[0] > b[0];
});
for (int i = 0; i <= n; ++i) {
fill(dp[i], dp[i] + n + 1, -inf);
}
dp[0][1] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= n; ++j) {
if (dp[i][j] != -inf) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
int k = min(n, j + a[i + 1][0] - 1);
if (k >= 0) {
dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i + 1][1]);
}
}
}
}
cout << *max_element(dp[n], dp[n] + n + 1);
return 0;
}
# | 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... |