# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792184 |
2023-07-24T17:09:53 Z |
CDuong |
Feast (NOI19_feast) |
C++17 |
|
85 ms |
11532 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 = oo / n;
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 |
72 ms |
10956 KB |
Output is correct |
2 |
Correct |
73 ms |
11268 KB |
Output is correct |
3 |
Correct |
74 ms |
11308 KB |
Output is correct |
4 |
Correct |
73 ms |
11260 KB |
Output is correct |
5 |
Correct |
76 ms |
11268 KB |
Output is correct |
6 |
Correct |
72 ms |
11076 KB |
Output is correct |
7 |
Correct |
71 ms |
11060 KB |
Output is correct |
8 |
Correct |
81 ms |
11296 KB |
Output is correct |
9 |
Correct |
71 ms |
11044 KB |
Output is correct |
10 |
Correct |
73 ms |
11208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
9444 KB |
Output is correct |
2 |
Correct |
64 ms |
9648 KB |
Output is correct |
3 |
Correct |
62 ms |
9372 KB |
Output is correct |
4 |
Correct |
64 ms |
9420 KB |
Output is correct |
5 |
Correct |
72 ms |
11040 KB |
Output is correct |
6 |
Correct |
63 ms |
9420 KB |
Output is correct |
7 |
Correct |
65 ms |
9608 KB |
Output is correct |
8 |
Correct |
74 ms |
11340 KB |
Output is correct |
9 |
Correct |
72 ms |
10928 KB |
Output is correct |
10 |
Correct |
64 ms |
9600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
11340 KB |
Output is correct |
2 |
Correct |
76 ms |
11336 KB |
Output is correct |
3 |
Correct |
78 ms |
11416 KB |
Output is correct |
4 |
Correct |
71 ms |
11196 KB |
Output is correct |
5 |
Correct |
85 ms |
11424 KB |
Output is correct |
6 |
Correct |
74 ms |
11400 KB |
Output is correct |
7 |
Correct |
76 ms |
11528 KB |
Output is correct |
8 |
Correct |
73 ms |
11400 KB |
Output is correct |
9 |
Correct |
75 ms |
11468 KB |
Output is correct |
10 |
Correct |
79 ms |
11532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
10956 KB |
Output is correct |
2 |
Correct |
73 ms |
11268 KB |
Output is correct |
3 |
Correct |
74 ms |
11308 KB |
Output is correct |
4 |
Correct |
73 ms |
11260 KB |
Output is correct |
5 |
Correct |
76 ms |
11268 KB |
Output is correct |
6 |
Correct |
72 ms |
11076 KB |
Output is correct |
7 |
Correct |
71 ms |
11060 KB |
Output is correct |
8 |
Correct |
81 ms |
11296 KB |
Output is correct |
9 |
Correct |
71 ms |
11044 KB |
Output is correct |
10 |
Correct |
73 ms |
11208 KB |
Output is correct |
11 |
Correct |
61 ms |
9444 KB |
Output is correct |
12 |
Correct |
64 ms |
9648 KB |
Output is correct |
13 |
Correct |
62 ms |
9372 KB |
Output is correct |
14 |
Correct |
64 ms |
9420 KB |
Output is correct |
15 |
Correct |
72 ms |
11040 KB |
Output is correct |
16 |
Correct |
63 ms |
9420 KB |
Output is correct |
17 |
Correct |
65 ms |
9608 KB |
Output is correct |
18 |
Correct |
74 ms |
11340 KB |
Output is correct |
19 |
Correct |
72 ms |
10928 KB |
Output is correct |
20 |
Correct |
64 ms |
9600 KB |
Output is correct |
21 |
Correct |
72 ms |
11340 KB |
Output is correct |
22 |
Correct |
76 ms |
11336 KB |
Output is correct |
23 |
Correct |
78 ms |
11416 KB |
Output is correct |
24 |
Correct |
71 ms |
11196 KB |
Output is correct |
25 |
Correct |
85 ms |
11424 KB |
Output is correct |
26 |
Correct |
74 ms |
11400 KB |
Output is correct |
27 |
Correct |
76 ms |
11528 KB |
Output is correct |
28 |
Correct |
73 ms |
11400 KB |
Output is correct |
29 |
Correct |
75 ms |
11468 KB |
Output is correct |
30 |
Correct |
79 ms |
11532 KB |
Output is correct |
31 |
Correct |
1 ms |
328 KB |
Output is correct |
32 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |