이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;
long long n, x, y, dp[2010][2010], maxx;
pair<long long,long long> a[2010];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].f >> a[i].s;
sort(a+1,a+n+1,greater<pair<long long,long long>>());
dp[0][0] = -1e18;
for (int i = 2; i <= n; i++) dp[0][i] = -1e18;
for (int i = 1; i <= n; i++) {
x = a[i].f; y = a[i].s;
for (int j = 0; j < n; j++) {
dp[i][j] = dp[i-1][j];
if (j-x+1 >= 0) dp[i][j] = max(dp[i][j],dp[i-1][j-x+1]+y);
}
dp[i][n] = dp[i-1][n];
for (int j = n-x+1; j <= n; j++) dp[i][n] = max(dp[i][n],dp[i-1][j]+y);
}
for (int i = 0; i <= n; i++) maxx = max(maxx,dp[n][i]);
cout << maxx << endl;
}
# | 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... |