# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1098050 |
2024-10-09T01:28:21 Z |
nngan267 |
Feast (NOI19_feast) |
C++17 |
|
125 ms |
14160 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
#define fi first
#define se second
#define pll pair<ll, ll>
#define db long double
#define plll pair<ll, pll>
const int maxn = 4e5+5;
const ll mod = 1e9+7;
const int iinf = 1e9+7;
const ll inf = 1e18+7;
const double eps = 1e-9;
const db pi = acos(-1);
int n, k;
int a[maxn];
void inp(){
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> a[i];
}
}
pll d[maxn][2];
pll check(ll lmb){
d[1][0] = {0, 0};
d[1][1] = {a[1] - lmb, 1};
for(int i=2; i<=n; i++){
d[i][0] = max(d[i-1][0], d[i-1][1]);
d[i][1] = max(make_pair(d[i-1][0].fi + a[i] - lmb, d[i-1][0].se + 1),
make_pair(d[i-1][1].fi + a[i], d[i-1][1].se));
}
return max({d[n][0], d[n][1]});
}
void solve(){
ll l = 0, r = inf;
ll res = 0;
while(l <= r){
ll mid = (l+r)/2;
if(check(mid).se >= k){
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << check(res).fi + res * k << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--){
inp();
solve();
}
cerr << "\nTime elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s.\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
13404 KB |
Output is correct |
2 |
Correct |
75 ms |
13648 KB |
Output is correct |
3 |
Correct |
57 ms |
13640 KB |
Output is correct |
4 |
Correct |
59 ms |
13648 KB |
Output is correct |
5 |
Correct |
59 ms |
13648 KB |
Output is correct |
6 |
Correct |
54 ms |
13428 KB |
Output is correct |
7 |
Correct |
55 ms |
13400 KB |
Output is correct |
8 |
Correct |
54 ms |
13608 KB |
Output is correct |
9 |
Correct |
54 ms |
13400 KB |
Output is correct |
10 |
Correct |
55 ms |
13452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11856 KB |
Output is correct |
2 |
Correct |
56 ms |
12124 KB |
Output is correct |
3 |
Correct |
45 ms |
11868 KB |
Output is correct |
4 |
Correct |
46 ms |
11864 KB |
Output is correct |
5 |
Correct |
51 ms |
13396 KB |
Output is correct |
6 |
Correct |
49 ms |
11864 KB |
Output is correct |
7 |
Correct |
49 ms |
11996 KB |
Output is correct |
8 |
Correct |
55 ms |
13580 KB |
Output is correct |
9 |
Correct |
51 ms |
13392 KB |
Output is correct |
10 |
Correct |
47 ms |
11868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
13916 KB |
Output is correct |
2 |
Correct |
89 ms |
13660 KB |
Output is correct |
3 |
Correct |
78 ms |
13908 KB |
Output is correct |
4 |
Correct |
77 ms |
13660 KB |
Output is correct |
5 |
Correct |
81 ms |
13648 KB |
Output is correct |
6 |
Correct |
80 ms |
13952 KB |
Output is correct |
7 |
Correct |
77 ms |
13864 KB |
Output is correct |
8 |
Correct |
76 ms |
13872 KB |
Output is correct |
9 |
Correct |
80 ms |
13832 KB |
Output is correct |
10 |
Correct |
79 ms |
13904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
480 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
480 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 |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
500 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
13404 KB |
Output is correct |
2 |
Correct |
75 ms |
13648 KB |
Output is correct |
3 |
Correct |
57 ms |
13640 KB |
Output is correct |
4 |
Correct |
59 ms |
13648 KB |
Output is correct |
5 |
Correct |
59 ms |
13648 KB |
Output is correct |
6 |
Correct |
54 ms |
13428 KB |
Output is correct |
7 |
Correct |
55 ms |
13400 KB |
Output is correct |
8 |
Correct |
54 ms |
13608 KB |
Output is correct |
9 |
Correct |
54 ms |
13400 KB |
Output is correct |
10 |
Correct |
55 ms |
13452 KB |
Output is correct |
11 |
Correct |
60 ms |
11856 KB |
Output is correct |
12 |
Correct |
56 ms |
12124 KB |
Output is correct |
13 |
Correct |
45 ms |
11868 KB |
Output is correct |
14 |
Correct |
46 ms |
11864 KB |
Output is correct |
15 |
Correct |
51 ms |
13396 KB |
Output is correct |
16 |
Correct |
49 ms |
11864 KB |
Output is correct |
17 |
Correct |
49 ms |
11996 KB |
Output is correct |
18 |
Correct |
55 ms |
13580 KB |
Output is correct |
19 |
Correct |
51 ms |
13392 KB |
Output is correct |
20 |
Correct |
47 ms |
11868 KB |
Output is correct |
21 |
Correct |
80 ms |
13916 KB |
Output is correct |
22 |
Correct |
89 ms |
13660 KB |
Output is correct |
23 |
Correct |
78 ms |
13908 KB |
Output is correct |
24 |
Correct |
77 ms |
13660 KB |
Output is correct |
25 |
Correct |
81 ms |
13648 KB |
Output is correct |
26 |
Correct |
80 ms |
13952 KB |
Output is correct |
27 |
Correct |
77 ms |
13864 KB |
Output is correct |
28 |
Correct |
76 ms |
13872 KB |
Output is correct |
29 |
Correct |
80 ms |
13832 KB |
Output is correct |
30 |
Correct |
79 ms |
13904 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
480 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 |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
500 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
110 ms |
13516 KB |
Output is correct |
62 |
Correct |
111 ms |
14160 KB |
Output is correct |
63 |
Correct |
96 ms |
13648 KB |
Output is correct |
64 |
Correct |
115 ms |
13904 KB |
Output is correct |
65 |
Correct |
116 ms |
13908 KB |
Output is correct |
66 |
Correct |
125 ms |
13996 KB |
Output is correct |
67 |
Correct |
115 ms |
13648 KB |
Output is correct |
68 |
Correct |
79 ms |
13916 KB |
Output is correct |
69 |
Correct |
78 ms |
13652 KB |
Output is correct |
70 |
Correct |
76 ms |
13396 KB |
Output is correct |