# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25578 | khsoo01 | 스트랩 (JOI14_straps) | C++11 | 29 ms | 33456 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<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
const ll inf = 1e18;
ll n, dt[2005][2005];
pair<ll,ll> a[2005];
int main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++) {
scanf("%lld%lld",&a[i].X,&a[i].Y);
a[i].X *= -1;
}
sort(a+1, a+1+n);
for(ll i=1;i<=n;i++) a[i].X *= -1;
for(ll i=0;i<=n;i++) {
for(ll j=0;j<=n;j++) dt[i][j] = -inf;
}
dt[0][1] = 0;
for(ll i=1;i<=n;i++) {
dt[i][0] = dt[i-1][0];
for(ll j=1;j<=n;j++) {
dt[i][j] = max(dt[i][j], dt[i-1][j]);
if(j + a[i].X - 1 >= 0) {
ll X = min(n, j+a[i].X-1);
dt[i][X] = max(dt[i][X], dt[i-1][j] + a[i].Y);
}
}
}
ll ans = 0;
for(ll i=0;i<=n;i++) ans = max(ans, dt[n][i]);
printf("%lld\n",ans);
}
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... |