# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25191 | junodeveloper | 스트랩 (JOI14_straps) | C++14 | 13 ms | 17692 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<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (int)2e9
using namespace std;
int e[2002][2002];
pair<int, int> p[2002];
int main() {
int n, i;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d%d", &p[i].first, &p[i].second);
p[i].first *= -1;
p[i].second *= -1;
}
sort(p + 1, p + n + 1);
for (i = 2; i <= n; i++) e[0][i] = -INF;
for (i = 1; i <= n; i++) {
int a = -p[i].first;
int b = -p[i].second;
if (!a) break;
for (int j = n; j >= 0; j--) {
e[i][j] = e[i - 1][j];
int t = max(0, j - a + 1);
if (e[i - 1][t] != -INF)
e[i][j] = max(e[i][j], e[i - 1][t] + b);
}
}
int last = i - 1;
vector<int> v;
for (; i <= n; i++)
if (-p[i].second > 0) v.push_back(-p[i].second);
int res = -INF, sum = 0;
for (i = 0; i <= n; i++) {
res = max(res, e[last][i] + sum);
if (i < v.size()) sum += v[i];
}
printf("%d", res);
return 0;
}
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... |