# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32109 | TAMREF | 스트랩 (JOI14_straps) | C++11 | 16 ms | 33436 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>
using namespace std;
using ii = pair<int,int>;
const int ilb = INT_MIN;
int dp[2005][2005], vis[2005][2005];
ii f[2005];
int n;
void input(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d %d",&f[i].first,&f[i].second);
sort(f+1,f+n+1,greater<ii>());
for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=ilb;
dp[0][1]=0;
}
void work(){
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++) dp[i][j]=dp[i-1][j];
for(int j=f[i].first;j-f[i].first+1<=n;j++){
if(dp[i-1][j-f[i].first+1]==ilb) continue;
dp[i][j]=max(dp[i][j],dp[i-1][j-f[i].first+1]+f[i].second);
}
}
}
int main(){
input();
work();
printf("%d\n",*max_element(dp[n],dp[n]+n+1));
}
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... |