# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
805103 |
2023-08-03T13:06:25 Z |
moe_solution(#10139) |
Fun Palace (CCO18_fun) |
C++17 |
|
67 ms |
78724 KB |
#include <bits/stdc++.h>
using namespace std;
const int N=1005,M=20005;
int n,e,a[N],b[N],dp[N][M],ans;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>e;
for(int i=1;i<n;i++) cin>>a[i]>>b[i];
for(int i=0;i<=n;i++) fill(dp[i],dp[i]+M,-(int)1e9);
for(int i=0;i<e;i++) dp[1][i]=i;
for(int i=1;i<n;i++){
int mx=-1e9;
for(int j=0;j<M;j++){
if(j>=a[i]+b[i]) dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
else if(j>=a[i]) dp[i+1][j-a[i]]=max(dp[i+1][j-a[i]],dp[i][j]);
else{
dp[i+1][j+b[i]]=max(dp[i+1][j+b[i]],dp[i][j]+b[i]);
mx=max(mx,dp[i][j]);
}
}
for(int j=0;j<b[i];j++) dp[i+1][j]=max(dp[i+1][j],mx+j);
}
for(int i=0;i<M;i++) ans=max(ans,dp[n][i]);
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
544 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
50 ms |
78604 KB |
Output is correct |
8 |
Correct |
59 ms |
77132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
544 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
548 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
11 ms |
15960 KB |
Output is correct |
15 |
Correct |
13 ms |
15572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
544 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
50 ms |
78604 KB |
Output is correct |
17 |
Correct |
59 ms |
77132 KB |
Output is correct |
18 |
Correct |
1 ms |
548 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
0 ms |
468 KB |
Output is correct |
22 |
Correct |
11 ms |
15960 KB |
Output is correct |
23 |
Correct |
13 ms |
15572 KB |
Output is correct |
24 |
Correct |
54 ms |
78696 KB |
Output is correct |
25 |
Correct |
50 ms |
77204 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
60 ms |
78724 KB |
Output is correct |
28 |
Correct |
59 ms |
78604 KB |
Output is correct |
29 |
Correct |
67 ms |
76608 KB |
Output is correct |
30 |
Correct |
51 ms |
54408 KB |
Output is correct |