# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1026001 |
2024-07-17T12:26:44 Z |
Zicrus |
Feast (NOI19_feast) |
C++17 |
|
207 ms |
5720 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k;
vector<ll> a;
pair<ll, ll> solve(ll p) {
ll dp = 0;
ll dpSeg = a[0] - p;
ll ps = 0;
ll psSeg = 1;
for (int i = 1; i < n; i++) {
ll tdp = dp, tdpSeg = dpSeg, tps = ps, tpsSeg = psSeg;
if (tdpSeg > tdp) {
dp = tdpSeg;
ps = tpsSeg;
}
if (tdp - p > tdpSeg) {
dpSeg = tdp - p;
psSeg = tps + 1;
}
dpSeg += a[i];
}
if (dpSeg > dp) {
dp = dpSeg;
ps = psSeg;
}
return {dp, ps};
}
int main() {
cin >> n >> k;
a = vector<ll>(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll l = 0, r = 1ll << 50;
ll bestK = 1ll << 50;
ll bestAns = 0;
ll pen = 0;
while (l <= r) {
ll mid = pen = (l + r) / 2;
bestK = solve(mid).second;
bestAns = solve(mid).first;
if (bestK > k) {
l = mid + 1;
}
else {
if (l == r) break;
r = mid;
}
}
ll val = bestAns + k * pen;
cout << val;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
5368 KB |
Output is correct |
2 |
Correct |
109 ms |
5460 KB |
Output is correct |
3 |
Correct |
101 ms |
5460 KB |
Output is correct |
4 |
Correct |
99 ms |
5716 KB |
Output is correct |
5 |
Correct |
100 ms |
5456 KB |
Output is correct |
6 |
Correct |
102 ms |
5460 KB |
Output is correct |
7 |
Correct |
99 ms |
5256 KB |
Output is correct |
8 |
Correct |
102 ms |
5432 KB |
Output is correct |
9 |
Correct |
97 ms |
5392 KB |
Output is correct |
10 |
Correct |
106 ms |
5464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
3732 KB |
Output is correct |
2 |
Correct |
67 ms |
3676 KB |
Output is correct |
3 |
Correct |
65 ms |
3668 KB |
Output is correct |
4 |
Correct |
68 ms |
3852 KB |
Output is correct |
5 |
Correct |
98 ms |
5460 KB |
Output is correct |
6 |
Correct |
69 ms |
3676 KB |
Output is correct |
7 |
Correct |
92 ms |
3664 KB |
Output is correct |
8 |
Correct |
107 ms |
5712 KB |
Output is correct |
9 |
Correct |
96 ms |
5460 KB |
Output is correct |
10 |
Correct |
66 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
5716 KB |
Output is correct |
2 |
Correct |
149 ms |
5516 KB |
Output is correct |
3 |
Correct |
138 ms |
5664 KB |
Output is correct |
4 |
Correct |
139 ms |
5656 KB |
Output is correct |
5 |
Correct |
150 ms |
5688 KB |
Output is correct |
6 |
Correct |
143 ms |
5676 KB |
Output is correct |
7 |
Correct |
136 ms |
5720 KB |
Output is correct |
8 |
Correct |
155 ms |
5716 KB |
Output is correct |
9 |
Correct |
143 ms |
5716 KB |
Output is correct |
10 |
Correct |
141 ms |
5716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
348 KB |
Output is correct |
10 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
436 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 |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
348 KB |
Output is correct |
10 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
436 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 |
436 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
448 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 |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
476 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 |
96 ms |
5368 KB |
Output is correct |
2 |
Correct |
109 ms |
5460 KB |
Output is correct |
3 |
Correct |
101 ms |
5460 KB |
Output is correct |
4 |
Correct |
99 ms |
5716 KB |
Output is correct |
5 |
Correct |
100 ms |
5456 KB |
Output is correct |
6 |
Correct |
102 ms |
5460 KB |
Output is correct |
7 |
Correct |
99 ms |
5256 KB |
Output is correct |
8 |
Correct |
102 ms |
5432 KB |
Output is correct |
9 |
Correct |
97 ms |
5392 KB |
Output is correct |
10 |
Correct |
106 ms |
5464 KB |
Output is correct |
11 |
Correct |
69 ms |
3732 KB |
Output is correct |
12 |
Correct |
67 ms |
3676 KB |
Output is correct |
13 |
Correct |
65 ms |
3668 KB |
Output is correct |
14 |
Correct |
68 ms |
3852 KB |
Output is correct |
15 |
Correct |
98 ms |
5460 KB |
Output is correct |
16 |
Correct |
69 ms |
3676 KB |
Output is correct |
17 |
Correct |
92 ms |
3664 KB |
Output is correct |
18 |
Correct |
107 ms |
5712 KB |
Output is correct |
19 |
Correct |
96 ms |
5460 KB |
Output is correct |
20 |
Correct |
66 ms |
3672 KB |
Output is correct |
21 |
Correct |
141 ms |
5716 KB |
Output is correct |
22 |
Correct |
149 ms |
5516 KB |
Output is correct |
23 |
Correct |
138 ms |
5664 KB |
Output is correct |
24 |
Correct |
139 ms |
5656 KB |
Output is correct |
25 |
Correct |
150 ms |
5688 KB |
Output is correct |
26 |
Correct |
143 ms |
5676 KB |
Output is correct |
27 |
Correct |
136 ms |
5720 KB |
Output is correct |
28 |
Correct |
155 ms |
5716 KB |
Output is correct |
29 |
Correct |
143 ms |
5716 KB |
Output is correct |
30 |
Correct |
141 ms |
5716 KB |
Output is correct |
31 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 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 |
0 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 |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 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 |
0 ms |
436 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
436 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
448 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 |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
476 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
207 ms |
5460 KB |
Output is correct |
62 |
Correct |
183 ms |
5716 KB |
Output is correct |
63 |
Correct |
172 ms |
5648 KB |
Output is correct |
64 |
Correct |
191 ms |
5716 KB |
Output is correct |
65 |
Correct |
190 ms |
5564 KB |
Output is correct |
66 |
Correct |
189 ms |
5716 KB |
Output is correct |
67 |
Correct |
192 ms |
5460 KB |
Output is correct |
68 |
Correct |
138 ms |
5680 KB |
Output is correct |
69 |
Correct |
142 ms |
5460 KB |
Output is correct |
70 |
Correct |
132 ms |
5556 KB |
Output is correct |