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<stdio.h>
#include<algorithm>
using namespace std;
long long dp[2001][2001];
int n;
pair<int, int> p[2000];
int main() {
scanf("%d", &n);
fill(&dp[0][2], &dp[n][n + 1], -1e10);
for (int i = 0; i <n; i++) scanf("%d %d", &p[i].first, &p[i].second);
sort(p, p + n);
for (int i = 1; i<=n; i++){
int a = p[n - i].first, b = p[n - i].second;
for (int j = 0; j <= n; j++){
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j + a - 1 >= 0 && j + a - 1 <= n)
dp[i][j + a - 1] = max(dp[i][j + a - 1], dp[i - 1][j] + b);
}
for (int j = n - 1; j >= 0; j--)
dp[i][j] = max(dp[i][j], dp[i][j + 1]);
}
printf("%lld", dp[n][0]);
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... |