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;
#define INF 2000000001
int n;
int dp[2005][2005];
struct _tuple {
int dan,val;
};
_tuple A[2005];
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;
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 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... |