# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21177 | junodeveloper | 스트랩 (JOI14_straps) | C++14 | 33 ms | 33368 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 (ll)2e9
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
ll n,i,d[2002][2002];
pl p[2002];
vector<ll> q;
int main() {
scanf("%lld", &n);
for(i=1;i<=n;i++) scanf("%lld%lld", &p[i].first, &p[i].second);
sort(p+1, p+n+1, [&](pl& a, pl& b) {
return a.first == b.first ? a.second > b.second : a.first > b.first;
});
for(i=2;i<=2000;i++) d[0][i] = -INF;
for(i=1;i<=n;i++) {
ll a = p[i].first;
ll b = p[i].second;
if(!a) break;
for(int j=2000;j>=0;j--) {
d[i][j] = d[i-1][j];
if(j < 2000) d[i][j] = max(d[i][j], d[i][j+1]);
if(j - a + 1 >= 0 && d[i-1][j-a+1] != -INF)
d[i][j] = max(d[i][j], d[i-1][j-a+1] + b);
}
}
ll t = i-1;
for(;i<=n;i++) if(p[i].second > 0) q.push_back(p[i].second);
ll r = -INF, s = 0;
for(i=0;i<=2000;i++) {
r = max(r, d[t][i] + s);
if(i < q.size()) s += q[i];
}
printf("%lld", r);
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... |