Submission #32116

#TimeUsernameProblemLanguageResultExecution timeMemory
32116dongwon0427스트랩 (JOI14_straps)C++98
100 / 100
23 ms17892 KiB
#include <bits/stdc++.h> using namespace std; #define INF 2000000001 int n; int dp[2005][2005]; struct _tuple { int dan,val; }; _tuple A[2005]; bool sf(_tuple a,_tuple b){ return a.dan>b.dan; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>A[i].dan>>A[i].val; sort(A+1,A+1+n,sf); for(int i=0;i<=n;i++) { for(int j=0;j<=2000;j++) { dp[i][j]=-INF; } } dp[0][1]=0; for(int i=1;i<=n;i++) { for(int j=0;j<=2000;j++) { dp[i][j]=dp[i-1][j]; } for(int j=1;j<=2000;j++) { dp[i][min(j-1+A[i].dan,2000)] = max(dp[i][min(j-1+A[i].dan,2000)] , dp[i-1][j] + A[i].val); } } int ans=0; for(int i=0;i<=2000;i++) { ans=max(ans,dp[n][i]); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...