# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30814 | TAMREF | 스트랩 (JOI14_straps) | C++11 | 946 ms | 262144 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 ilb INT_MIN
using namespace std;
unordered_map<int,int> dp[2005], vis[2005];
pair<int,int> f[2005];
int N;
void input(){
scanf("%d",&N);
for(int i=0;i<N;i++) scanf("%d %d",&f[i].first,&f[i].second);
sort(f,f+N,greater<pair<int,int>>());
dp[0][1]=0;
}
void work_dp(){
for(int i=0;i<N;i++){
for(auto x : dp[i]){
if(!vis[i+1][x.first]){
dp[i+1][x.first]=ilb;
vis[i+1][x.first]=1;
}
dp[i+1][x.first]=max(dp[i+1][x.first],x.second);
if(!x.first) continue;
if(!vis[i+1][x.first+f[i].first-1]){
dp[i+1][x.first+f[i].first-1]=ilb;
vis[i+1][x.first+f[i].first-1]=1;
}
dp[i+1][x.first+f[i].first-1]=max(dp[i+1][x.first+f[i].first-1],x.second+f[i].second);
}
}
}
void output(){
int t=0;
for(auto x : dp[N]) t=max(t,x.second);
printf("%d\n",t);
}
int main(){
input();
work_dp();
output();
}
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... |