#include<bits/stdc++.h>
#define int long long
#define double long double
#define PB push_back
#define maxn 300007
#define bit(x,i) ((x>>i)&1)
#define S second
#define F first
#define MP make_pair
using namespace std;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
const int inf = 1e9*3e5;
const int mod = 1e9+7;
const double PI = acos(-1);
const double eps = 1e-3;
int n,k,a[maxn];
pdi f[maxn][2];
void readData(){
cin>>n>>k;
for (int i=1;i<=n;i++) cin>>a[i];
}
bool check(double dak){
f[0][0]={0,0};
f[0][1]={-inf,0};
for (int i=1;i<=n;i++){
f[i][0]=max(f[i-1][0],f[i-1][1]);
f[i][1]=max((pdi){f[i-1][1].F+a[i],f[i-1][1].S},(pdi){f[i-1][0].F+a[i]-dak,f[i-1][0].S+1});
}
int mim=max(f[n][0],f[n][1]).S;
return mim>=k;
}
void solve(){
double l=0,r=inf,dak;
while (l+eps<r){
double mid=(l+r)/2;
if (check(mid)) l=mid;
else r=mid;
}
dak=l;
check(dak);
int ans=round(dak*k+max(f[n][0],f[n][1]).F);
cout<<ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
readData();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
24148 KB |
Output is correct |
2 |
Correct |
196 ms |
24404 KB |
Output is correct |
3 |
Correct |
191 ms |
24452 KB |
Output is correct |
4 |
Correct |
192 ms |
24408 KB |
Output is correct |
5 |
Correct |
193 ms |
24400 KB |
Output is correct |
6 |
Correct |
182 ms |
24304 KB |
Output is correct |
7 |
Correct |
180 ms |
24052 KB |
Output is correct |
8 |
Correct |
189 ms |
24656 KB |
Output is correct |
9 |
Correct |
186 ms |
24148 KB |
Output is correct |
10 |
Correct |
187 ms |
24368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
22636 KB |
Output is correct |
2 |
Correct |
185 ms |
22620 KB |
Output is correct |
3 |
Correct |
182 ms |
22604 KB |
Output is correct |
4 |
Correct |
181 ms |
22488 KB |
Output is correct |
5 |
Correct |
190 ms |
24144 KB |
Output is correct |
6 |
Correct |
200 ms |
22640 KB |
Output is correct |
7 |
Correct |
191 ms |
22708 KB |
Output is correct |
8 |
Correct |
202 ms |
24260 KB |
Output is correct |
9 |
Correct |
196 ms |
24144 KB |
Output is correct |
10 |
Correct |
190 ms |
22688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
232 ms |
24508 KB |
Output is correct |
2 |
Correct |
228 ms |
24404 KB |
Output is correct |
3 |
Correct |
238 ms |
24660 KB |
Output is correct |
4 |
Correct |
225 ms |
24272 KB |
Output is correct |
5 |
Correct |
228 ms |
24556 KB |
Output is correct |
6 |
Correct |
231 ms |
24656 KB |
Output is correct |
7 |
Correct |
230 ms |
24400 KB |
Output is correct |
8 |
Correct |
224 ms |
24556 KB |
Output is correct |
9 |
Correct |
233 ms |
24624 KB |
Output is correct |
10 |
Correct |
228 ms |
24400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2400 KB |
Output is correct |
11 |
Correct |
1 ms |
2400 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2400 KB |
Output is correct |
16 |
Correct |
1 ms |
2400 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2400 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2400 KB |
Output is correct |
11 |
Correct |
1 ms |
2400 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2400 KB |
Output is correct |
16 |
Correct |
1 ms |
2400 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2400 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
3 ms |
2840 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2536 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
24148 KB |
Output is correct |
2 |
Correct |
196 ms |
24404 KB |
Output is correct |
3 |
Correct |
191 ms |
24452 KB |
Output is correct |
4 |
Correct |
192 ms |
24408 KB |
Output is correct |
5 |
Correct |
193 ms |
24400 KB |
Output is correct |
6 |
Correct |
182 ms |
24304 KB |
Output is correct |
7 |
Correct |
180 ms |
24052 KB |
Output is correct |
8 |
Correct |
189 ms |
24656 KB |
Output is correct |
9 |
Correct |
186 ms |
24148 KB |
Output is correct |
10 |
Correct |
187 ms |
24368 KB |
Output is correct |
11 |
Correct |
187 ms |
22636 KB |
Output is correct |
12 |
Correct |
185 ms |
22620 KB |
Output is correct |
13 |
Correct |
182 ms |
22604 KB |
Output is correct |
14 |
Correct |
181 ms |
22488 KB |
Output is correct |
15 |
Correct |
190 ms |
24144 KB |
Output is correct |
16 |
Correct |
200 ms |
22640 KB |
Output is correct |
17 |
Correct |
191 ms |
22708 KB |
Output is correct |
18 |
Correct |
202 ms |
24260 KB |
Output is correct |
19 |
Correct |
196 ms |
24144 KB |
Output is correct |
20 |
Correct |
190 ms |
22688 KB |
Output is correct |
21 |
Correct |
232 ms |
24508 KB |
Output is correct |
22 |
Correct |
228 ms |
24404 KB |
Output is correct |
23 |
Correct |
238 ms |
24660 KB |
Output is correct |
24 |
Correct |
225 ms |
24272 KB |
Output is correct |
25 |
Correct |
228 ms |
24556 KB |
Output is correct |
26 |
Correct |
231 ms |
24656 KB |
Output is correct |
27 |
Correct |
230 ms |
24400 KB |
Output is correct |
28 |
Correct |
224 ms |
24556 KB |
Output is correct |
29 |
Correct |
233 ms |
24624 KB |
Output is correct |
30 |
Correct |
228 ms |
24400 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2392 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2400 KB |
Output is correct |
41 |
Correct |
1 ms |
2400 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2400 KB |
Output is correct |
46 |
Correct |
1 ms |
2400 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2400 KB |
Output is correct |
49 |
Correct |
1 ms |
2400 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
3 ms |
2840 KB |
Output is correct |
52 |
Correct |
2 ms |
2652 KB |
Output is correct |
53 |
Correct |
2 ms |
2536 KB |
Output is correct |
54 |
Correct |
2 ms |
2652 KB |
Output is correct |
55 |
Correct |
2 ms |
2652 KB |
Output is correct |
56 |
Correct |
2 ms |
2652 KB |
Output is correct |
57 |
Correct |
2 ms |
2652 KB |
Output is correct |
58 |
Correct |
2 ms |
2652 KB |
Output is correct |
59 |
Correct |
2 ms |
2652 KB |
Output is correct |
60 |
Correct |
2 ms |
2648 KB |
Output is correct |
61 |
Correct |
290 ms |
24496 KB |
Output is correct |
62 |
Correct |
294 ms |
24632 KB |
Output is correct |
63 |
Correct |
251 ms |
24404 KB |
Output is correct |
64 |
Correct |
304 ms |
24924 KB |
Output is correct |
65 |
Correct |
306 ms |
24404 KB |
Output is correct |
66 |
Correct |
306 ms |
24656 KB |
Output is correct |
67 |
Correct |
300 ms |
24400 KB |
Output is correct |
68 |
Correct |
236 ms |
24404 KB |
Output is correct |
69 |
Correct |
228 ms |
24400 KB |
Output is correct |
70 |
Correct |
224 ms |
24404 KB |
Output is correct |