# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39692 | 14kg | 스트랩 (JOI14_straps) | C++11 | 13 ms | 1136 KiB |
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>
#define INF 2000000000
#define max2(x,y) (x>y?x:y)
#define min2(x,y) (x<y?x:y)
using namespace std;
int n, dp[2001];
pair<int, int> in[2001];
int main() {
int x, y, w, out = 0;
scanf("%d", &n);
for (int i = 2; i <= n; i++) dp[i] = -INF;
for (int i = 1; i <= n; i++) scanf("%d %d", &in[i].first, &in[i].second);
sort(in + 1, in + n + 1);
for (int k = n; k >= 1; k--) {
x = in[k].first - 1, y = in[k].second;
if (x < 0) {
for (int i = 0; i < n; i++) dp[i] = max2(dp[i], dp[i + 1] + y);
}
else {
for (int i = n; i >= 0; i--) {
w = min2(n, i + x);
dp[w] = max2(dp[w], dp[i] + y);
}
}
}
for (int i = 0; i <= n; i++) out = max2(out, dp[i]);
printf("%d", out);
}
Compilation message (stderr)
# | 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... |