# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791938 |
2023-07-24T12:43:22 Z |
trucmai |
Feast (NOI19_feast) |
C++17 |
|
105 ms |
8012 KB |
//i_love_aisukiuwu
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/home/trucmai/.vim/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
void open(){
if(fopen("i.inp","r")){
freopen("i.inp","r",stdin);
freopen("o.out","w",stdout);
}
}
#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "
const int MN1 = 1e6 + 5,MN2 = 2e3 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,k,a[MN1],pf[MN1];
void solve(){
cin>>n>>k;
for(ll i = 1;i <= n;++i){
cin>>a[i];
pf[i] = pf[i-1] + a[i];
}
ll l = 0,r = 3e14,res = 0;
auto dp=[&](ll x)->pi{
pi mx = {0,0},f = {0,0};
for(ll i = 1;i <= n;++i){
f = max(f,{mx.fi + pf[i] - x,mx.se - 1});
mx = max(mx,{f.fi - pf[i],f.se});
}
f.se *= -1;
return f;
};
while(l <= r){
ll m = (r+l) >> 1;
auto [val,cnt] = dp(m);
debug(l,r,cnt);
if(cnt <= k){
r = m - 1;
res = val + k*m;
}
else l = m + 1;
}
cout<<res;
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
open();
ll t = 1; //cin>>t;
while(t--) solve();
#ifdef LOCAL
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
Compilation message
feast.cpp: In function 'void open()':
feast.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen("i.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
feast.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen("o.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
4820 KB |
Output is correct |
2 |
Correct |
35 ms |
4920 KB |
Output is correct |
3 |
Correct |
47 ms |
5188 KB |
Output is correct |
4 |
Correct |
46 ms |
4976 KB |
Output is correct |
5 |
Correct |
40 ms |
4924 KB |
Output is correct |
6 |
Correct |
34 ms |
4820 KB |
Output is correct |
7 |
Correct |
40 ms |
4812 KB |
Output is correct |
8 |
Correct |
37 ms |
4964 KB |
Output is correct |
9 |
Correct |
35 ms |
4828 KB |
Output is correct |
10 |
Correct |
41 ms |
4896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
4904 KB |
Output is correct |
2 |
Correct |
38 ms |
4976 KB |
Output is correct |
3 |
Correct |
30 ms |
4896 KB |
Output is correct |
4 |
Correct |
49 ms |
4884 KB |
Output is correct |
5 |
Correct |
44 ms |
4808 KB |
Output is correct |
6 |
Correct |
36 ms |
4888 KB |
Output is correct |
7 |
Correct |
30 ms |
5020 KB |
Output is correct |
8 |
Correct |
42 ms |
4976 KB |
Output is correct |
9 |
Correct |
51 ms |
4812 KB |
Output is correct |
10 |
Correct |
33 ms |
4928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
4840 KB |
Output is correct |
2 |
Correct |
78 ms |
7884 KB |
Output is correct |
3 |
Correct |
61 ms |
7952 KB |
Output is correct |
4 |
Correct |
65 ms |
7888 KB |
Output is correct |
5 |
Correct |
69 ms |
7892 KB |
Output is correct |
6 |
Correct |
71 ms |
7996 KB |
Output is correct |
7 |
Correct |
61 ms |
7948 KB |
Output is correct |
8 |
Correct |
60 ms |
7960 KB |
Output is correct |
9 |
Correct |
69 ms |
8008 KB |
Output is correct |
10 |
Correct |
71 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
372 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
4820 KB |
Output is correct |
2 |
Correct |
35 ms |
4920 KB |
Output is correct |
3 |
Correct |
47 ms |
5188 KB |
Output is correct |
4 |
Correct |
46 ms |
4976 KB |
Output is correct |
5 |
Correct |
40 ms |
4924 KB |
Output is correct |
6 |
Correct |
34 ms |
4820 KB |
Output is correct |
7 |
Correct |
40 ms |
4812 KB |
Output is correct |
8 |
Correct |
37 ms |
4964 KB |
Output is correct |
9 |
Correct |
35 ms |
4828 KB |
Output is correct |
10 |
Correct |
41 ms |
4896 KB |
Output is correct |
11 |
Correct |
54 ms |
4904 KB |
Output is correct |
12 |
Correct |
38 ms |
4976 KB |
Output is correct |
13 |
Correct |
30 ms |
4896 KB |
Output is correct |
14 |
Correct |
49 ms |
4884 KB |
Output is correct |
15 |
Correct |
44 ms |
4808 KB |
Output is correct |
16 |
Correct |
36 ms |
4888 KB |
Output is correct |
17 |
Correct |
30 ms |
5020 KB |
Output is correct |
18 |
Correct |
42 ms |
4976 KB |
Output is correct |
19 |
Correct |
51 ms |
4812 KB |
Output is correct |
20 |
Correct |
33 ms |
4928 KB |
Output is correct |
21 |
Correct |
67 ms |
4840 KB |
Output is correct |
22 |
Correct |
78 ms |
7884 KB |
Output is correct |
23 |
Correct |
61 ms |
7952 KB |
Output is correct |
24 |
Correct |
65 ms |
7888 KB |
Output is correct |
25 |
Correct |
69 ms |
7892 KB |
Output is correct |
26 |
Correct |
71 ms |
7996 KB |
Output is correct |
27 |
Correct |
61 ms |
7948 KB |
Output is correct |
28 |
Correct |
60 ms |
7960 KB |
Output is correct |
29 |
Correct |
69 ms |
8008 KB |
Output is correct |
30 |
Correct |
71 ms |
8012 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
372 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
368 KB |
Output is correct |
61 |
Correct |
101 ms |
7544 KB |
Output is correct |
62 |
Correct |
99 ms |
7836 KB |
Output is correct |
63 |
Correct |
82 ms |
7508 KB |
Output is correct |
64 |
Correct |
89 ms |
7772 KB |
Output is correct |
65 |
Correct |
105 ms |
7764 KB |
Output is correct |
66 |
Correct |
102 ms |
7736 KB |
Output is correct |
67 |
Correct |
93 ms |
7636 KB |
Output is correct |
68 |
Correct |
69 ms |
7716 KB |
Output is correct |
69 |
Correct |
65 ms |
7616 KB |
Output is correct |
70 |
Correct |
62 ms |
7560 KB |
Output is correct |