# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791755 |
2023-07-24T09:36:18 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
119 ms |
8532 KB |
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("arch=skylake")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 3e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, k, a[mxN];
ll pref[mxN], ans;
pair<ll, int> dp[mxN];
ll calc(int l, int r) {
if(l > r) return 0;
return pref[r] - pref[l - 1];
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
ll l = -oo / n, r = 0;
while(l < r) {
ll mid = (l + r + 1) >> 1;
pair<ll, int> maxx = {0, 0}, doesntexist = {0, 0};
for(int i = 1; i <= n; ++i) {
ll tmp = maxx.ff + pref[i] + mid;
if(dp[i - 1].ff == tmp) dp[i] = min(dp[i - 1], pair{tmp, maxx.ss + 1});
else dp[i] = max(dp[i - 1], pair{tmp, maxx.ss + 1});
if(maxx.ff == dp[i].ff - pref[i]) maxx = min(maxx, pair{dp[i].ff - pref[i], dp[i].ss});
else maxx = max(maxx, pair{dp[i].ff - pref[i], dp[i].ss});
if(dp[i].ff == doesntexist.ff) doesntexist = min(doesntexist, dp[i]);
else doesntexist = max(doesntexist, dp[i]);
}
if(doesntexist.ss <= k) l = mid;
else r = mid - 1;
}
pair<ll, int> maxx = {0, 0}, doesntexist = {0, 0};
for(int i = 1; i <= n; ++i) {
ll tmp = maxx.ff + pref[i] + l;
if(dp[i - 1].ff == tmp) dp[i] = min(dp[i - 1], pair{tmp, maxx.ss + 1});
else dp[i] = max(dp[i - 1], pair{tmp, maxx.ss + 1});
if(maxx.ff == dp[i].ff - pref[i]) maxx = min(maxx, pair{dp[i].ff - pref[i], dp[i].ss});
else maxx = max(maxx, pair{dp[i].ff - pref[i], dp[i].ss});
if(dp[i].ff == doesntexist.ff) doesntexist = min(doesntexist, dp[i]);
else doesntexist = max(doesntexist, dp[i]);
}
cout << doesntexist.ff - doesntexist.ss * l << endl;
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8276 KB |
Output is correct |
2 |
Correct |
76 ms |
8428 KB |
Output is correct |
3 |
Correct |
74 ms |
8472 KB |
Output is correct |
4 |
Correct |
72 ms |
8352 KB |
Output is correct |
5 |
Correct |
74 ms |
8392 KB |
Output is correct |
6 |
Correct |
75 ms |
8280 KB |
Output is correct |
7 |
Correct |
81 ms |
8264 KB |
Output is correct |
8 |
Correct |
77 ms |
8324 KB |
Output is correct |
9 |
Correct |
72 ms |
8288 KB |
Output is correct |
10 |
Correct |
76 ms |
8380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
8284 KB |
Output is correct |
2 |
Correct |
66 ms |
8504 KB |
Output is correct |
3 |
Correct |
74 ms |
8320 KB |
Output is correct |
4 |
Correct |
66 ms |
8388 KB |
Output is correct |
5 |
Correct |
71 ms |
8288 KB |
Output is correct |
6 |
Correct |
69 ms |
8268 KB |
Output is correct |
7 |
Correct |
75 ms |
8532 KB |
Output is correct |
8 |
Correct |
73 ms |
8480 KB |
Output is correct |
9 |
Correct |
75 ms |
8256 KB |
Output is correct |
10 |
Correct |
68 ms |
8472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8404 KB |
Output is correct |
2 |
Correct |
90 ms |
8316 KB |
Output is correct |
3 |
Correct |
90 ms |
8332 KB |
Output is correct |
4 |
Correct |
80 ms |
8344 KB |
Output is correct |
5 |
Correct |
92 ms |
8408 KB |
Output is correct |
6 |
Correct |
72 ms |
8460 KB |
Output is correct |
7 |
Correct |
80 ms |
8404 KB |
Output is correct |
8 |
Correct |
81 ms |
8296 KB |
Output is correct |
9 |
Correct |
70 ms |
8508 KB |
Output is correct |
10 |
Correct |
73 ms |
8500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
388 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
388 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
388 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 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 |
0 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 |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8276 KB |
Output is correct |
2 |
Correct |
76 ms |
8428 KB |
Output is correct |
3 |
Correct |
74 ms |
8472 KB |
Output is correct |
4 |
Correct |
72 ms |
8352 KB |
Output is correct |
5 |
Correct |
74 ms |
8392 KB |
Output is correct |
6 |
Correct |
75 ms |
8280 KB |
Output is correct |
7 |
Correct |
81 ms |
8264 KB |
Output is correct |
8 |
Correct |
77 ms |
8324 KB |
Output is correct |
9 |
Correct |
72 ms |
8288 KB |
Output is correct |
10 |
Correct |
76 ms |
8380 KB |
Output is correct |
11 |
Correct |
60 ms |
8284 KB |
Output is correct |
12 |
Correct |
66 ms |
8504 KB |
Output is correct |
13 |
Correct |
74 ms |
8320 KB |
Output is correct |
14 |
Correct |
66 ms |
8388 KB |
Output is correct |
15 |
Correct |
71 ms |
8288 KB |
Output is correct |
16 |
Correct |
69 ms |
8268 KB |
Output is correct |
17 |
Correct |
75 ms |
8532 KB |
Output is correct |
18 |
Correct |
73 ms |
8480 KB |
Output is correct |
19 |
Correct |
75 ms |
8256 KB |
Output is correct |
20 |
Correct |
68 ms |
8472 KB |
Output is correct |
21 |
Correct |
71 ms |
8404 KB |
Output is correct |
22 |
Correct |
90 ms |
8316 KB |
Output is correct |
23 |
Correct |
90 ms |
8332 KB |
Output is correct |
24 |
Correct |
80 ms |
8344 KB |
Output is correct |
25 |
Correct |
92 ms |
8408 KB |
Output is correct |
26 |
Correct |
72 ms |
8460 KB |
Output is correct |
27 |
Correct |
80 ms |
8404 KB |
Output is correct |
28 |
Correct |
81 ms |
8296 KB |
Output is correct |
29 |
Correct |
70 ms |
8508 KB |
Output is correct |
30 |
Correct |
73 ms |
8500 KB |
Output is correct |
31 |
Correct |
0 ms |
388 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 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 |
0 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 |
340 KB |
Output is correct |
55 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
108 ms |
8320 KB |
Output is correct |
62 |
Correct |
119 ms |
8516 KB |
Output is correct |
63 |
Correct |
86 ms |
8300 KB |
Output is correct |
64 |
Correct |
100 ms |
8352 KB |
Output is correct |
65 |
Correct |
89 ms |
8364 KB |
Output is correct |
66 |
Correct |
109 ms |
8432 KB |
Output is correct |
67 |
Correct |
88 ms |
8308 KB |
Output is correct |
68 |
Correct |
73 ms |
8464 KB |
Output is correct |
69 |
Correct |
85 ms |
8312 KB |
Output is correct |
70 |
Correct |
70 ms |
8264 KB |
Output is correct |