#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 10;
const long double EPS = 1e-3;
int N, K;
int a[MAX];
pair<long double, int> dp[MAX][2];
bool OK(long double lambda){
dp[0][0] = make_pair(0.0, 0);
dp[0][1] = make_pair(-1.18, 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][1].first + a[i], dp[i - 1][1].second),
make_pair(dp[i - 1][0].first + a[i] - lambda, dp[i - 1][0].second + 1));
}
return max(dp[N][0].second, dp[N][1].second) >= K;
}
int main(){
ios_base::sync_with_stdio(0);
cin >> N >> K;
for(int i=1; i<=N; i++){
cin >> a[i];
}
long double lo = 0, hi = (long double)1e14;
while(lo + EPS < hi){
long double mid = (lo + hi) / 2;
if(OK(mid)){
lo = mid;
}
else{
hi = mid;
}
}
OK(lo);
cout << (long long)round((long long)lo * K + max(dp[N][0], dp[N][1]).first) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
20228 KB |
Output is correct |
2 |
Correct |
187 ms |
23096 KB |
Output is correct |
3 |
Correct |
181 ms |
23124 KB |
Output is correct |
4 |
Correct |
206 ms |
22932 KB |
Output is correct |
5 |
Correct |
179 ms |
23096 KB |
Output is correct |
6 |
Correct |
181 ms |
23168 KB |
Output is correct |
7 |
Correct |
182 ms |
23028 KB |
Output is correct |
8 |
Correct |
186 ms |
23108 KB |
Output is correct |
9 |
Correct |
186 ms |
23032 KB |
Output is correct |
10 |
Correct |
182 ms |
23076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
173 ms |
20232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
20256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
20228 KB |
Output is correct |
2 |
Correct |
187 ms |
23096 KB |
Output is correct |
3 |
Correct |
181 ms |
23124 KB |
Output is correct |
4 |
Correct |
206 ms |
22932 KB |
Output is correct |
5 |
Correct |
179 ms |
23096 KB |
Output is correct |
6 |
Correct |
181 ms |
23168 KB |
Output is correct |
7 |
Correct |
182 ms |
23028 KB |
Output is correct |
8 |
Correct |
186 ms |
23108 KB |
Output is correct |
9 |
Correct |
186 ms |
23032 KB |
Output is correct |
10 |
Correct |
182 ms |
23076 KB |
Output is correct |
11 |
Incorrect |
173 ms |
20232 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |