#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int n, k;
vector<long long> a;
vector<vector<pair<long long, long long> > > DP;
pair<long long, long long> dp(long long lambda)
{
DP[0][0] = { 0, 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]);
}
int main()
{
cin >> n >> k;
DP.resize(n + 1, vector<pair<long long, long long>>(2, { LLONG_MIN, 0 }));
a.resize(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
long long l = 0, r = 3e14, lambda;
while ( r - l > 1)
{
lambda = (l + r) / 2;
auto m = dp(lambda);
if (m.second > k) l = lambda;
else r = lambda;
}
auto megoldas = dp(r);
cout << megoldas.first + megoldas.second * r;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
23136 KB |
Output is correct |
2 |
Correct |
197 ms |
23388 KB |
Output is correct |
3 |
Correct |
208 ms |
23900 KB |
Output is correct |
4 |
Correct |
202 ms |
23716 KB |
Output is correct |
5 |
Correct |
201 ms |
23576 KB |
Output is correct |
6 |
Correct |
196 ms |
23196 KB |
Output is correct |
7 |
Correct |
195 ms |
23180 KB |
Output is correct |
8 |
Correct |
224 ms |
23648 KB |
Output is correct |
9 |
Correct |
181 ms |
23240 KB |
Output is correct |
10 |
Correct |
196 ms |
23388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
23184 KB |
Output is correct |
2 |
Correct |
166 ms |
23892 KB |
Output is correct |
3 |
Correct |
154 ms |
23128 KB |
Output is correct |
4 |
Correct |
140 ms |
23508 KB |
Output is correct |
5 |
Correct |
201 ms |
23388 KB |
Output is correct |
6 |
Correct |
165 ms |
23280 KB |
Output is correct |
7 |
Correct |
147 ms |
23912 KB |
Output is correct |
8 |
Correct |
203 ms |
23736 KB |
Output is correct |
9 |
Correct |
192 ms |
23132 KB |
Output is correct |
10 |
Correct |
156 ms |
23736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
204 ms |
23644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
23136 KB |
Output is correct |
2 |
Correct |
197 ms |
23388 KB |
Output is correct |
3 |
Correct |
208 ms |
23900 KB |
Output is correct |
4 |
Correct |
202 ms |
23716 KB |
Output is correct |
5 |
Correct |
201 ms |
23576 KB |
Output is correct |
6 |
Correct |
196 ms |
23196 KB |
Output is correct |
7 |
Correct |
195 ms |
23180 KB |
Output is correct |
8 |
Correct |
224 ms |
23648 KB |
Output is correct |
9 |
Correct |
181 ms |
23240 KB |
Output is correct |
10 |
Correct |
196 ms |
23388 KB |
Output is correct |
11 |
Correct |
160 ms |
23184 KB |
Output is correct |
12 |
Correct |
166 ms |
23892 KB |
Output is correct |
13 |
Correct |
154 ms |
23128 KB |
Output is correct |
14 |
Correct |
140 ms |
23508 KB |
Output is correct |
15 |
Correct |
201 ms |
23388 KB |
Output is correct |
16 |
Correct |
165 ms |
23280 KB |
Output is correct |
17 |
Correct |
147 ms |
23912 KB |
Output is correct |
18 |
Correct |
203 ms |
23736 KB |
Output is correct |
19 |
Correct |
192 ms |
23132 KB |
Output is correct |
20 |
Correct |
156 ms |
23736 KB |
Output is correct |
21 |
Incorrect |
204 ms |
23644 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |