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 <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;
long long n, x, y, dp[2010][2010], maxx;
int main() {
cin >> n;
dp[0][0] = -1e18;
for (int i = 2; i <= n; i++) dp[0][i] = -1e18;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
for (int j = 0; j < n; j++) {
dp[i][j] = dp[i-1][j];
if (j-x+1 >= 0) dp[i][j] = max(dp[i][j],dp[i-1][j-x+1]+y);
}
dp[i][n] = dp[i-1][n];
for (int j = n-x+1; j <= n; j++) dp[i][n] = max(dp[i][n],dp[i-1][j]+y);
}
for (int i = 0; i <= n; i++) maxx = max(maxx,dp[n][i]);
cout << maxx << endl;
}
# | 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... |