# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1025690 |
2024-07-17T08:45:51 Z |
Gr1sen |
Feast (NOI19_feast) |
C++17 |
|
1000 ms |
96520 KB |
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define pi pair<ll, ll>
#define ppi pair<ll, pi>
#define vp vector<ppi>
#define vvp vector<vp>
ll n, k;
vi L;
vvp M;
ppi oink(ll c, ll p = 0, bool q = 0) {
if (p == n) return {0, {0, 0}};
if (M[p][q].first != -1) return M[p][q];
if (q) {
if (L[p] >= 0) {
ppi a = oink(c, p+1, 1);
a.first += L[p];
a.second.second += L[p];
return M[p][q] = a;
}
ppi a = oink(c, p+1, 1);
a.first += L[p];
a.second.second += L[p];
ppi b = oink(c, p+1, 0);
return M[p][q] = max(a, b);
}
ppi a = oink(c, p+1, 1);
a.first += L[p] - c;
a.second.second += L[p];
a.second.first++;
ppi b = oink(c, p+1, 0);
return M[p][q] = max(a, b);
}
/*
*/
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
L = vi(n);
for (auto &i : L) cin >> i;
ll l = 0, r = 1000000000000;
ll ans;
while (l < r) {
//cerr << l << " " << r << endl;
M = vvp(n, vp(2, {-1, {-1, -1}}));
ll m = (l+r)/2;
ppi a = oink(m);
if (a.second.first == k) {
ans = a.second.second;
break;
}
if (a.second.first > k) {
l = m+1;
continue;
}
ans = a.second.second;
r = m;
}
cout << ans << "\n";
}
/*
6 1
1 -2 3 -1 5 -6
6 2
1 2 3 -10 5 6
6 4
-1 -2 -1 0 -5 -1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
93624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
560 ms |
94376 KB |
Output is correct |
2 |
Correct |
431 ms |
96484 KB |
Output is correct |
3 |
Correct |
400 ms |
94152 KB |
Output is correct |
4 |
Execution timed out |
1039 ms |
94892 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
270 ms |
95568 KB |
Output is correct |
2 |
Correct |
284 ms |
94376 KB |
Output is correct |
3 |
Correct |
236 ms |
95316 KB |
Output is correct |
4 |
Correct |
230 ms |
94348 KB |
Output is correct |
5 |
Correct |
220 ms |
95312 KB |
Output is correct |
6 |
Correct |
271 ms |
95824 KB |
Output is correct |
7 |
Correct |
345 ms |
96248 KB |
Output is correct |
8 |
Correct |
284 ms |
95340 KB |
Output is correct |
9 |
Correct |
181 ms |
96520 KB |
Output is correct |
10 |
Correct |
340 ms |
96404 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
3 ms |
856 KB |
Output is correct |
22 |
Correct |
5 ms |
860 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
3 ms |
860 KB |
Output is correct |
29 |
Correct |
3 ms |
860 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
93624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |