#include <bits/stdc++.h>
using namespace std;
constexpr size_t N = 300000;
int64_t a[N];
pair<int64_t, int64_t> dp(size_t n, int64_t lambda)
{
int64_t mu = 0, nu = 0, p = 0, cnt = 0;
for (size_t i = 0; i < n; ++i)
{
p += a[i];
if (mu + p - lambda > nu)
nu = mu + p - lambda, ++cnt;
mu = max(mu, nu - p);
}
return {nu, cnt};
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n, k;
cin >> n >> k;
for (size_t i = 0; i < n; ++i)
cin >> a[i];
int64_t u = 0, v = 1LL << 41;
while (u < v)
{
if (dp(n, (u + v) / 2).second <= k)
v = (u + v) / 2;
else
u = (u + v) / 2 + 1;
}
auto const [objective_val, cnt] = dp(n, u);
cout << objective_val + cnt * u << '\n';
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:34:39: warning: comparison of integer expressions of different signedness: 'long int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
34 | if (dp(n, (u + v) / 2).second <= k)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
5324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
3660 KB |
Output is correct |
2 |
Correct |
38 ms |
3744 KB |
Output is correct |
3 |
Correct |
36 ms |
3656 KB |
Output is correct |
4 |
Incorrect |
41 ms |
3860 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
5676 KB |
Output is correct |
2 |
Correct |
52 ms |
5508 KB |
Output is correct |
3 |
Correct |
54 ms |
5628 KB |
Output is correct |
4 |
Correct |
55 ms |
5468 KB |
Output is correct |
5 |
Correct |
53 ms |
5632 KB |
Output is correct |
6 |
Correct |
52 ms |
5644 KB |
Output is correct |
7 |
Correct |
65 ms |
5784 KB |
Output is correct |
8 |
Correct |
53 ms |
5628 KB |
Output is correct |
9 |
Correct |
55 ms |
5776 KB |
Output is correct |
10 |
Correct |
53 ms |
5680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
5324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |