#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
const int MAXN = 3e5+3;
ll arr[MAXN];
pair<long double, ll> mem[MAXN][2];
ll n, k;
bool isVisited[MAXN][2];
long double lambda;
pair<long double, ll> dp(ll index, int inInterval){
if (index == n) return {0, 0};
if (isVisited[index][inInterval])return mem[index][inInterval];
isVisited[index][inInterval] = true;
if (inInterval){
//fortsätt -> ingen penalty
pair<long double, ll> cont = {dp(index+1, 1).first+arr[index], dp(index+1, 1).second};
pair<long double, ll> stop = {dp(index+1, 0).first, dp(index+1, 0).second};
//stanna -> penalty
return mem[index][inInterval] = max(cont, stop);
} else {
//köp inget
pair<long double, ll> cont = {dp(index+1, 0).first, dp(index+1, 0).second};
//starta
pair<long double, ll> start = {dp(index+1, 1).first + arr[index] - lambda, dp(index+1, 1).second+1};
return mem[index][inInterval] = max(cont, start);
}
}
bool check(long double la){
lambda = la;
for (int i = 0; i < n; i++){
isVisited[i][0] = false;
isVisited[i][1] = false;
}
//cout << la << " " << dp(0, 0).first << " " << dp(0, 0).second << endl;
return dp(0,0).second >= k;
}
int main(){
scoobydoobydoo();
cin >> n >> k;
for (int i = 0; i < n; i++)cin >> arr[i];
long double a = 0, b = 1e20;
while (a+(1e-5) < b){
long double mid = (a+b)/2.0;
if (check(mid)){
a = mid;
} else {
b = mid;
}
}
check(a);
//cout << fixed << setprecision(5);
//cout << a << endl;
//cout << check(6.99) << endl;
//cout << check(7.99) << endl;
ll ans = round(a*k + mem[0][0].first);
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
76628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1032 ms |
77136 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1049 ms |
77768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4560 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4560 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4560 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4444 KB |
Output is correct |
21 |
Correct |
8 ms |
4956 KB |
Output is correct |
22 |
Correct |
9 ms |
4952 KB |
Output is correct |
23 |
Correct |
8 ms |
4700 KB |
Output is correct |
24 |
Correct |
8 ms |
4956 KB |
Output is correct |
25 |
Correct |
8 ms |
4956 KB |
Output is correct |
26 |
Correct |
8 ms |
4956 KB |
Output is correct |
27 |
Correct |
9 ms |
4956 KB |
Output is correct |
28 |
Correct |
10 ms |
4956 KB |
Output is correct |
29 |
Correct |
8 ms |
4844 KB |
Output is correct |
30 |
Correct |
8 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
76628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |