# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
809127 | urd05 | Fun Palace (CCO18_fun) | C++17 | 62 ms | 82772 KiB |
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;
int n;
int e;
int a[1000];
int b[1000];
int dp[1000][50001]; //정확히.
const int MAX=20000;
int main() {
scanf("%d\n%d\n",&n,&e);
for(int i=0;i<n-1;i++) {
scanf("%d %d",&a[i],&b[i]);
}
for(int i=0;i<=MAX;i++) {
dp[n-1][i]=i;
}
for(int i=n-2;i>=0;i--) {
int mx=0;
for(int j=0;j<b[i];j++) {
mx=max(mx,dp[i+1][j]);
}
for(int j=0;j<=MAX;j++) {
if (j<a[i]) {
dp[i][j]=max(mx+j,dp[i+1][b[i]+j]);
}
else if (j<a[i]+b[i]) {
dp[i][j]=dp[i+1][j-a[i]]+a[i];
}
else {
dp[i][j]=dp[i+1][j];
}
}
}
int ret=0;
for(int i=0;i<e;i++) {
ret=max(ret,dp[0][i]);
}
printf("%d",ret);
return 0;
}
Compilation message (stderr)
# | 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... |