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 fi first
#define se second
const int N = 2e3 + 5;
long long n,dp[N][N];
pair<long long,long long> rope[N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i=1;i<=n;i++) cin >> rope[i].fi >> rope[i].se;
for(int i=0;i<=n;i++){
for(int j=1;j<=n;j++){
dp[i][j] = -1e18;
}
}
sort(rope+1, rope+1+n);
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
dp[i][j] = max(dp[i-1][min((long long)i-1, j + rope[i].fi - 1)], dp[i-1][j-1]) + rope[i].se;
dp[i][j] = max(dp[i][j], dp[i-1][j]);
}
}
cout << max(dp[n][0], dp[n][1]);
}
# | 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... |