# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
605361 |
2022-07-25T16:21:34 Z |
lunchbox |
Feast (NOI19_feast) |
C++17 |
|
114 ms |
2936 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
void update(pair<long long, int>& a, const pair<long long, int>& b) {
if (a.first < b.first || (a.first == b.first && a.second > b.second))
a = b;
}
pair<long long, int> solve(int n, long long *pp, long long t) {
pair<long long, int> last{0, 0}, dp{0, 0};
for (int i = 0; i < n; i++) {
update(dp, make_pair(last.first + pp[i] - t, last.second + 1));
update(last, make_pair(dp.first - pp[i], dp.second));
}
return dp;
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
static long long pp[N];
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
pp[i] = (i > 0 ? pp[i - 1] : 0) + a;
}
long long low = -1, hi = 0x3f3f3f3f3f3f3f3f;
while (low < hi) {
long long t = (low + hi + 1) / 2;
if (solve(n, pp, t).second >= k)
low = t;
else
hi = t - 1;
}
printf("%lld\n", solve(n, pp, low).first + low * k);
return 0;
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
2812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
2780 KB |
Output is correct |
2 |
Correct |
55 ms |
2764 KB |
Output is correct |
3 |
Correct |
59 ms |
2760 KB |
Output is correct |
4 |
Incorrect |
42 ms |
2788 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
2824 KB |
Output is correct |
2 |
Correct |
100 ms |
2832 KB |
Output is correct |
3 |
Correct |
83 ms |
2892 KB |
Output is correct |
4 |
Correct |
79 ms |
2836 KB |
Output is correct |
5 |
Correct |
89 ms |
2856 KB |
Output is correct |
6 |
Correct |
114 ms |
2916 KB |
Output is correct |
7 |
Correct |
100 ms |
2860 KB |
Output is correct |
8 |
Correct |
79 ms |
2852 KB |
Output is correct |
9 |
Correct |
94 ms |
2768 KB |
Output is correct |
10 |
Correct |
100 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
2812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |