Submission #157202

#TimeUsernameProblemLanguageResultExecution timeMemory
157202puppies_and_rainbows스트랩 (JOI14_straps)C++14
100 / 100
86 ms63300 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int dp[2005][2005]; pair<int, int> a[2005]; int maxdp[2005][2005]; signed main() { int n; cin>>n; for(int i=1; i<=n; i++) { cin>>a[i].first>>a[i].second; a[i].first--; } sort(a+1, a+n+1); for(int i=1; i<=n/2; i++) { swap(a[i], a[n+1-i]); } for(int i=0; i<=n+1; i++) { dp[0][i]=-100000000000; } for(int i=n+1; i>1; i--) { maxdp[0][i]=-100000000000; } dp[0][1]=0; for(int i=1; i<=n; i++) { for(int j=0; j<=n+1; j++) { dp[i][j]=dp[i-1][j]; } for(int j=a[i].first+1; j<=n; j++) { dp[i][j]=max(dp[i][j], dp[i-1][j-a[i].first]+a[i].second); } dp[i][0]=max(dp[i-1][0], maxdp[i-1][1]+a[i].second); dp[i][n]=max(dp[i][n], maxdp[i-1][max(1ll, n-a[i].first)]+a[i].second); maxdp[i][n+1]=dp[i][n+1]; for(int j=n; j>=1; j--) { maxdp[i][j]=max(maxdp[i][j+1], dp[i][j]); } } // for(int i=1; i<=n; i++) // { // for(int j=1; j<=n; j++) // { // cout<<dp[i][j]<<" "; // } // cout<<endl; // } int ans=0; for(int i=0; i<=n; i++) { ans=max(ans, dp[n][i]); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...