# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017560 |
2024-07-09T08:52:03 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
956 ms |
24172 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
pair<int,int> solve(int l,int a[],int n){
vector<vector<pair<int,int>>> DP(n,vector<pair<int,int>>(2));
DP[0][0]={0,0};
DP[0][1]={a[0]-l,1};
for(int i=1;i<n;i++){
DP[i][0]=max(DP[i-1][0],DP[i-1][1]);
DP[i][1]=max(DP[i-1][1],{DP[i-1][0].first-l,DP[i-1][0].second+1});
DP[i][1].first+=a[i];
}
return max(DP[n-1][0],DP[n-1][1]);
}
signed main() {
int n,k;
cin >> n >> k;
int a[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
int low=0,high=1e18;
low--,high++;
while(high-low>1){
int mid=(high-low)/2+low;
if(solve(mid,a,n).second>=k){
low=mid;
}
else{
high=mid;
}
}
if(low==-1){
low++;
}
cout << solve(low,a,n).first+low*k;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
829 ms |
23212 KB |
Output is correct |
2 |
Correct |
840 ms |
23620 KB |
Output is correct |
3 |
Correct |
832 ms |
24172 KB |
Output is correct |
4 |
Correct |
823 ms |
23780 KB |
Output is correct |
5 |
Correct |
869 ms |
23660 KB |
Output is correct |
6 |
Correct |
802 ms |
23216 KB |
Output is correct |
7 |
Correct |
853 ms |
23216 KB |
Output is correct |
8 |
Correct |
803 ms |
23700 KB |
Output is correct |
9 |
Correct |
896 ms |
23292 KB |
Output is correct |
10 |
Correct |
832 ms |
23748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
784 ms |
23236 KB |
Output is correct |
2 |
Correct |
824 ms |
23888 KB |
Output is correct |
3 |
Correct |
814 ms |
23396 KB |
Output is correct |
4 |
Correct |
820 ms |
23572 KB |
Output is correct |
5 |
Correct |
935 ms |
23268 KB |
Output is correct |
6 |
Correct |
885 ms |
23316 KB |
Output is correct |
7 |
Correct |
867 ms |
24084 KB |
Output is correct |
8 |
Correct |
891 ms |
23816 KB |
Output is correct |
9 |
Correct |
797 ms |
23208 KB |
Output is correct |
10 |
Correct |
797 ms |
23804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
23704 KB |
Output is correct |
2 |
Correct |
855 ms |
23376 KB |
Output is correct |
3 |
Correct |
835 ms |
23592 KB |
Output is correct |
4 |
Correct |
828 ms |
23560 KB |
Output is correct |
5 |
Correct |
949 ms |
23708 KB |
Output is correct |
6 |
Correct |
881 ms |
23736 KB |
Output is correct |
7 |
Correct |
912 ms |
23820 KB |
Output is correct |
8 |
Correct |
927 ms |
23612 KB |
Output is correct |
9 |
Correct |
878 ms |
23924 KB |
Output is correct |
10 |
Correct |
956 ms |
23840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
344 KB |
Output is correct |
22 |
Correct |
4 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
5 ms |
348 KB |
Output is correct |
27 |
Correct |
5 ms |
348 KB |
Output is correct |
28 |
Correct |
4 ms |
580 KB |
Output is correct |
29 |
Correct |
4 ms |
580 KB |
Output is correct |
30 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
829 ms |
23212 KB |
Output is correct |
2 |
Correct |
840 ms |
23620 KB |
Output is correct |
3 |
Correct |
832 ms |
24172 KB |
Output is correct |
4 |
Correct |
823 ms |
23780 KB |
Output is correct |
5 |
Correct |
869 ms |
23660 KB |
Output is correct |
6 |
Correct |
802 ms |
23216 KB |
Output is correct |
7 |
Correct |
853 ms |
23216 KB |
Output is correct |
8 |
Correct |
803 ms |
23700 KB |
Output is correct |
9 |
Correct |
896 ms |
23292 KB |
Output is correct |
10 |
Correct |
832 ms |
23748 KB |
Output is correct |
11 |
Correct |
784 ms |
23236 KB |
Output is correct |
12 |
Correct |
824 ms |
23888 KB |
Output is correct |
13 |
Correct |
814 ms |
23396 KB |
Output is correct |
14 |
Correct |
820 ms |
23572 KB |
Output is correct |
15 |
Correct |
935 ms |
23268 KB |
Output is correct |
16 |
Correct |
885 ms |
23316 KB |
Output is correct |
17 |
Correct |
867 ms |
24084 KB |
Output is correct |
18 |
Correct |
891 ms |
23816 KB |
Output is correct |
19 |
Correct |
797 ms |
23208 KB |
Output is correct |
20 |
Correct |
797 ms |
23804 KB |
Output is correct |
21 |
Correct |
831 ms |
23704 KB |
Output is correct |
22 |
Correct |
855 ms |
23376 KB |
Output is correct |
23 |
Correct |
835 ms |
23592 KB |
Output is correct |
24 |
Correct |
828 ms |
23560 KB |
Output is correct |
25 |
Correct |
949 ms |
23708 KB |
Output is correct |
26 |
Correct |
881 ms |
23736 KB |
Output is correct |
27 |
Correct |
912 ms |
23820 KB |
Output is correct |
28 |
Correct |
927 ms |
23612 KB |
Output is correct |
29 |
Correct |
878 ms |
23924 KB |
Output is correct |
30 |
Correct |
956 ms |
23840 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
4 ms |
344 KB |
Output is correct |
52 |
Correct |
4 ms |
348 KB |
Output is correct |
53 |
Correct |
6 ms |
348 KB |
Output is correct |
54 |
Correct |
4 ms |
348 KB |
Output is correct |
55 |
Correct |
4 ms |
348 KB |
Output is correct |
56 |
Correct |
5 ms |
348 KB |
Output is correct |
57 |
Correct |
5 ms |
348 KB |
Output is correct |
58 |
Correct |
4 ms |
580 KB |
Output is correct |
59 |
Correct |
4 ms |
580 KB |
Output is correct |
60 |
Correct |
4 ms |
348 KB |
Output is correct |
61 |
Correct |
929 ms |
23380 KB |
Output is correct |
62 |
Correct |
932 ms |
23980 KB |
Output is correct |
63 |
Correct |
831 ms |
23328 KB |
Output is correct |
64 |
Correct |
925 ms |
23936 KB |
Output is correct |
65 |
Correct |
874 ms |
23988 KB |
Output is correct |
66 |
Correct |
909 ms |
23744 KB |
Output is correct |
67 |
Correct |
918 ms |
23412 KB |
Output is correct |
68 |
Correct |
876 ms |
23892 KB |
Output is correct |
69 |
Correct |
813 ms |
23288 KB |
Output is correct |
70 |
Correct |
861 ms |
23416 KB |
Output is correct |