Submission #978901

# Submission time Handle Problem Language Result Execution time Memory
978901 2024-05-10T01:19:17 Z Kiet07 Feast (NOI19_feast) C++14
100 / 100
159 ms 15196 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,a[300005];
pair<int,int>find(int x){
	pair<int,int> dp[n][2];
	dp[0][0]={0,0};
	dp[0][1]={a[0]-x,1};
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
		dp[i][1]=max(make_pair(dp[i-1][1].first+a[i],dp[i-1][1].second),make_pair(dp[i-1][0].first+a[i]-x,dp[i-1][0].second+1));
	}
	return max(dp[n-1][0],dp[n-1][1]);
}
signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int l=0,r=1e18,ans=0,res=0;
	while(l<=r){
		int m=(l+r)/2;
		auto it=find(m);
		if(it.second>=k){
			ans=m;
			l=m+1;
		}
		else{
			r=m-1;
		}
	}
	cout<<find(ans).first+ans*k;
	return 0;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:22:23: warning: unused variable 'res' [-Wunused-variable]
   22 |  int l=0,r=1e18,ans=0,res=0;
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 14428 KB Output is correct
2 Correct 93 ms 14672 KB Output is correct
3 Correct 96 ms 15036 KB Output is correct
4 Correct 94 ms 14940 KB Output is correct
5 Correct 93 ms 14684 KB Output is correct
6 Correct 91 ms 14620 KB Output is correct
7 Correct 94 ms 14440 KB Output is correct
8 Correct 95 ms 14908 KB Output is correct
9 Correct 90 ms 14416 KB Output is correct
10 Correct 94 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 13008 KB Output is correct
2 Correct 84 ms 13288 KB Output is correct
3 Correct 80 ms 12892 KB Output is correct
4 Correct 80 ms 12884 KB Output is correct
5 Correct 87 ms 14416 KB Output is correct
6 Correct 82 ms 12972 KB Output is correct
7 Correct 85 ms 13148 KB Output is correct
8 Correct 91 ms 14972 KB Output is correct
9 Correct 94 ms 14584 KB Output is correct
10 Correct 83 ms 13216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 14944 KB Output is correct
2 Correct 111 ms 14876 KB Output is correct
3 Correct 111 ms 15016 KB Output is correct
4 Correct 108 ms 14836 KB Output is correct
5 Correct 110 ms 14932 KB Output is correct
6 Correct 129 ms 15108 KB Output is correct
7 Correct 111 ms 14932 KB Output is correct
8 Correct 110 ms 14940 KB Output is correct
9 Correct 113 ms 15196 KB Output is correct
10 Correct 113 ms 14932 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 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 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 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 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 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 556 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 14428 KB Output is correct
2 Correct 93 ms 14672 KB Output is correct
3 Correct 96 ms 15036 KB Output is correct
4 Correct 94 ms 14940 KB Output is correct
5 Correct 93 ms 14684 KB Output is correct
6 Correct 91 ms 14620 KB Output is correct
7 Correct 94 ms 14440 KB Output is correct
8 Correct 95 ms 14908 KB Output is correct
9 Correct 90 ms 14416 KB Output is correct
10 Correct 94 ms 14672 KB Output is correct
11 Correct 79 ms 13008 KB Output is correct
12 Correct 84 ms 13288 KB Output is correct
13 Correct 80 ms 12892 KB Output is correct
14 Correct 80 ms 12884 KB Output is correct
15 Correct 87 ms 14416 KB Output is correct
16 Correct 82 ms 12972 KB Output is correct
17 Correct 85 ms 13148 KB Output is correct
18 Correct 91 ms 14972 KB Output is correct
19 Correct 94 ms 14584 KB Output is correct
20 Correct 83 ms 13216 KB Output is correct
21 Correct 109 ms 14944 KB Output is correct
22 Correct 111 ms 14876 KB Output is correct
23 Correct 111 ms 15016 KB Output is correct
24 Correct 108 ms 14836 KB Output is correct
25 Correct 110 ms 14932 KB Output is correct
26 Correct 129 ms 15108 KB Output is correct
27 Correct 111 ms 14932 KB Output is correct
28 Correct 110 ms 14940 KB Output is correct
29 Correct 113 ms 15196 KB Output is correct
30 Correct 113 ms 14932 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 1 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 556 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 151 ms 14684 KB Output is correct
62 Correct 147 ms 15192 KB Output is correct
63 Correct 126 ms 14676 KB Output is correct
64 Correct 154 ms 14956 KB Output is correct
65 Correct 159 ms 15184 KB Output is correct
66 Correct 154 ms 14940 KB Output is correct
67 Correct 152 ms 14836 KB Output is correct
68 Correct 114 ms 14928 KB Output is correct
69 Correct 130 ms 14736 KB Output is correct
70 Correct 107 ms 14680 KB Output is correct