#include <cstdio>
#include <cmath>
#include <climits>
#include <functional>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;
#define N 300005
#define ALL(x) x.begin(), x.end()
int n, k, a[N];
long long p[N];
pair<ll, int> dp[N][2];
const long double EPS = 1e-3;
int check(ll lambda)
{
dp[0][1] = make_pair(-1e18, 0);
for (int i = 1; i <= n; ++i)
{
dp[i][0] = max({dp[i-1][0], dp[i-1][1]});
dp[i][1] = max(make_pair(dp[i-1][0].first + a[i] - lambda, dp[i-1][0].second + 1),
make_pair(dp[i-1][1].first + a[i], dp[i-1][1].second));
}
return max(dp[n][0], dp[n][1]).second >= k;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
ll l = 0, r = 3e14+5;
while (l <= r)
{
ll y = (l+r)/2;
if (check(y)) l = y + 1;
else r = y - 1;
}
check(l-1);
cout << (long long)round(k * (l-1) + max(dp[n][0], dp[n][1]).first);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
160 ms |
13144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
13148 KB |
Output is correct |
2 |
Correct |
147 ms |
13360 KB |
Output is correct |
3 |
Correct |
146 ms |
13400 KB |
Output is correct |
4 |
Incorrect |
160 ms |
13148 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
13148 KB |
Output is correct |
2 |
Correct |
155 ms |
13140 KB |
Output is correct |
3 |
Correct |
159 ms |
13332 KB |
Output is correct |
4 |
Correct |
160 ms |
13140 KB |
Output is correct |
5 |
Correct |
160 ms |
13148 KB |
Output is correct |
6 |
Correct |
163 ms |
13136 KB |
Output is correct |
7 |
Correct |
163 ms |
13264 KB |
Output is correct |
8 |
Correct |
155 ms |
13332 KB |
Output is correct |
9 |
Correct |
160 ms |
13104 KB |
Output is correct |
10 |
Correct |
163 ms |
13500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
160 ms |
13144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |