# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
935823 |
2024-02-29T15:20:25 Z |
imarn |
Feast (NOI19_feast) |
C++14 |
|
108 ms |
15440 KB |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
const int N=3e5+5;
ll a[N]{0};
pll dp[N];
pll mx[N];
pll solve(ll x,int n){
dp[0]=mx[0]={0,0};
for(int i=1;i<=n;i++){
dp[i] = max(dp[i-1],{mx[i-1].f+a[i]-x,mx[i-1].s-1});
mx[i] = max(mx[i-1],{dp[i].f-a[i],dp[i].s});
}return dp[n];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,k;cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i],a[i]+=a[i-1];
ll l=0,r=1e12;
while(l<r){
ll m=(l+r)>>1;
if(-solve(m,n).s<=k)r=m;
else l=m+1;
}
cout<<solve(l,n).f+l*k;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
11860 KB |
Output is correct |
2 |
Correct |
58 ms |
12152 KB |
Output is correct |
3 |
Correct |
60 ms |
12124 KB |
Output is correct |
4 |
Correct |
56 ms |
12164 KB |
Output is correct |
5 |
Correct |
55 ms |
12112 KB |
Output is correct |
6 |
Correct |
54 ms |
12376 KB |
Output is correct |
7 |
Correct |
55 ms |
12124 KB |
Output is correct |
8 |
Correct |
56 ms |
12152 KB |
Output is correct |
9 |
Correct |
67 ms |
12124 KB |
Output is correct |
10 |
Correct |
58 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
12124 KB |
Output is correct |
2 |
Correct |
48 ms |
12124 KB |
Output is correct |
3 |
Correct |
46 ms |
12124 KB |
Output is correct |
4 |
Correct |
48 ms |
12124 KB |
Output is correct |
5 |
Correct |
56 ms |
14676 KB |
Output is correct |
6 |
Correct |
47 ms |
13148 KB |
Output is correct |
7 |
Correct |
48 ms |
13320 KB |
Output is correct |
8 |
Correct |
56 ms |
14936 KB |
Output is correct |
9 |
Correct |
55 ms |
14676 KB |
Output is correct |
10 |
Correct |
48 ms |
13144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
12120 KB |
Output is correct |
2 |
Correct |
67 ms |
12124 KB |
Output is correct |
3 |
Correct |
68 ms |
12112 KB |
Output is correct |
4 |
Correct |
66 ms |
12120 KB |
Output is correct |
5 |
Correct |
67 ms |
12072 KB |
Output is correct |
6 |
Correct |
67 ms |
12112 KB |
Output is correct |
7 |
Correct |
67 ms |
12112 KB |
Output is correct |
8 |
Correct |
66 ms |
12140 KB |
Output is correct |
9 |
Correct |
67 ms |
12124 KB |
Output is correct |
10 |
Correct |
69 ms |
12188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4596 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
11860 KB |
Output is correct |
2 |
Correct |
58 ms |
12152 KB |
Output is correct |
3 |
Correct |
60 ms |
12124 KB |
Output is correct |
4 |
Correct |
56 ms |
12164 KB |
Output is correct |
5 |
Correct |
55 ms |
12112 KB |
Output is correct |
6 |
Correct |
54 ms |
12376 KB |
Output is correct |
7 |
Correct |
55 ms |
12124 KB |
Output is correct |
8 |
Correct |
56 ms |
12152 KB |
Output is correct |
9 |
Correct |
67 ms |
12124 KB |
Output is correct |
10 |
Correct |
58 ms |
12112 KB |
Output is correct |
11 |
Correct |
47 ms |
12124 KB |
Output is correct |
12 |
Correct |
48 ms |
12124 KB |
Output is correct |
13 |
Correct |
46 ms |
12124 KB |
Output is correct |
14 |
Correct |
48 ms |
12124 KB |
Output is correct |
15 |
Correct |
56 ms |
14676 KB |
Output is correct |
16 |
Correct |
47 ms |
13148 KB |
Output is correct |
17 |
Correct |
48 ms |
13320 KB |
Output is correct |
18 |
Correct |
56 ms |
14936 KB |
Output is correct |
19 |
Correct |
55 ms |
14676 KB |
Output is correct |
20 |
Correct |
48 ms |
13144 KB |
Output is correct |
21 |
Correct |
66 ms |
12120 KB |
Output is correct |
22 |
Correct |
67 ms |
12124 KB |
Output is correct |
23 |
Correct |
68 ms |
12112 KB |
Output is correct |
24 |
Correct |
66 ms |
12120 KB |
Output is correct |
25 |
Correct |
67 ms |
12072 KB |
Output is correct |
26 |
Correct |
67 ms |
12112 KB |
Output is correct |
27 |
Correct |
67 ms |
12112 KB |
Output is correct |
28 |
Correct |
66 ms |
12140 KB |
Output is correct |
29 |
Correct |
67 ms |
12124 KB |
Output is correct |
30 |
Correct |
69 ms |
12188 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
1 ms |
4444 KB |
Output is correct |
47 |
Correct |
1 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4444 KB |
Output is correct |
55 |
Correct |
1 ms |
4444 KB |
Output is correct |
56 |
Correct |
1 ms |
4596 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
58 |
Correct |
1 ms |
4444 KB |
Output is correct |
59 |
Correct |
1 ms |
4444 KB |
Output is correct |
60 |
Correct |
1 ms |
4444 KB |
Output is correct |
61 |
Correct |
106 ms |
15104 KB |
Output is correct |
62 |
Correct |
105 ms |
15428 KB |
Output is correct |
63 |
Correct |
79 ms |
14928 KB |
Output is correct |
64 |
Correct |
104 ms |
15188 KB |
Output is correct |
65 |
Correct |
108 ms |
15440 KB |
Output is correct |
66 |
Correct |
106 ms |
14932 KB |
Output is correct |
67 |
Correct |
104 ms |
14924 KB |
Output is correct |
68 |
Correct |
70 ms |
15204 KB |
Output is correct |
69 |
Correct |
70 ms |
14940 KB |
Output is correct |
70 |
Correct |
70 ms |
14916 KB |
Output is correct |