#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
const int N=3e5+5;
pll dp[N];
ll qs[N]{0};
int n,m,k;
pll solve(ll x){
pll mex={0,0};
for(int i=1;i<=n;i++){
dp[i]=max(dp[i-1],{mex.f+qs[i]-x,mex.s-1});
mex=max(mex,{dp[i].f-qs[i],dp[i].s});
}return dp[n];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>k;dp[0]={0,0};
for(int i=1;i<=n;i++)cin>>qs[i],qs[i]+=qs[i-1];
ll l=0,r=1e12;
while(l<r){
ll md=(l+r)>>1;
if(-solve(md).s<=k)r=md;
else l=md+1;
}cout<<solve(l).f+l*k;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
10068 KB |
Output is correct |
2 |
Correct |
46 ms |
10228 KB |
Output is correct |
3 |
Correct |
47 ms |
10320 KB |
Output is correct |
4 |
Correct |
47 ms |
10064 KB |
Output is correct |
5 |
Correct |
46 ms |
10068 KB |
Output is correct |
6 |
Correct |
45 ms |
10076 KB |
Output is correct |
7 |
Correct |
45 ms |
10064 KB |
Output is correct |
8 |
Correct |
46 ms |
10068 KB |
Output is correct |
9 |
Correct |
45 ms |
10076 KB |
Output is correct |
10 |
Correct |
51 ms |
10320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
8488 KB |
Output is correct |
2 |
Correct |
42 ms |
8444 KB |
Output is correct |
3 |
Correct |
41 ms |
8284 KB |
Output is correct |
4 |
Correct |
40 ms |
8540 KB |
Output is correct |
5 |
Correct |
46 ms |
10072 KB |
Output is correct |
6 |
Correct |
40 ms |
8468 KB |
Output is correct |
7 |
Correct |
43 ms |
8620 KB |
Output is correct |
8 |
Correct |
56 ms |
10324 KB |
Output is correct |
9 |
Correct |
45 ms |
10068 KB |
Output is correct |
10 |
Correct |
40 ms |
8584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10324 KB |
Output is correct |
2 |
Correct |
65 ms |
10364 KB |
Output is correct |
3 |
Correct |
67 ms |
10476 KB |
Output is correct |
4 |
Correct |
66 ms |
10224 KB |
Output is correct |
5 |
Correct |
72 ms |
10320 KB |
Output is correct |
6 |
Correct |
68 ms |
10332 KB |
Output is correct |
7 |
Correct |
66 ms |
10492 KB |
Output is correct |
8 |
Correct |
65 ms |
10352 KB |
Output is correct |
9 |
Correct |
65 ms |
10332 KB |
Output is correct |
10 |
Correct |
67 ms |
10320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2512 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2512 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
10068 KB |
Output is correct |
2 |
Correct |
46 ms |
10228 KB |
Output is correct |
3 |
Correct |
47 ms |
10320 KB |
Output is correct |
4 |
Correct |
47 ms |
10064 KB |
Output is correct |
5 |
Correct |
46 ms |
10068 KB |
Output is correct |
6 |
Correct |
45 ms |
10076 KB |
Output is correct |
7 |
Correct |
45 ms |
10064 KB |
Output is correct |
8 |
Correct |
46 ms |
10068 KB |
Output is correct |
9 |
Correct |
45 ms |
10076 KB |
Output is correct |
10 |
Correct |
51 ms |
10320 KB |
Output is correct |
11 |
Correct |
51 ms |
8488 KB |
Output is correct |
12 |
Correct |
42 ms |
8444 KB |
Output is correct |
13 |
Correct |
41 ms |
8284 KB |
Output is correct |
14 |
Correct |
40 ms |
8540 KB |
Output is correct |
15 |
Correct |
46 ms |
10072 KB |
Output is correct |
16 |
Correct |
40 ms |
8468 KB |
Output is correct |
17 |
Correct |
43 ms |
8620 KB |
Output is correct |
18 |
Correct |
56 ms |
10324 KB |
Output is correct |
19 |
Correct |
45 ms |
10068 KB |
Output is correct |
20 |
Correct |
40 ms |
8584 KB |
Output is correct |
21 |
Correct |
66 ms |
10324 KB |
Output is correct |
22 |
Correct |
65 ms |
10364 KB |
Output is correct |
23 |
Correct |
67 ms |
10476 KB |
Output is correct |
24 |
Correct |
66 ms |
10224 KB |
Output is correct |
25 |
Correct |
72 ms |
10320 KB |
Output is correct |
26 |
Correct |
68 ms |
10332 KB |
Output is correct |
27 |
Correct |
66 ms |
10492 KB |
Output is correct |
28 |
Correct |
65 ms |
10352 KB |
Output is correct |
29 |
Correct |
65 ms |
10332 KB |
Output is correct |
30 |
Correct |
67 ms |
10320 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2392 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 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 |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2512 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
1 ms |
2392 KB |
Output is correct |
52 |
Correct |
1 ms |
2392 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
2 ms |
2396 KB |
Output is correct |
55 |
Correct |
1 ms |
2396 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
1 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
94 ms |
10356 KB |
Output is correct |
62 |
Correct |
94 ms |
10480 KB |
Output is correct |
63 |
Correct |
83 ms |
10580 KB |
Output is correct |
64 |
Correct |
96 ms |
10488 KB |
Output is correct |
65 |
Correct |
96 ms |
10332 KB |
Output is correct |
66 |
Correct |
96 ms |
10328 KB |
Output is correct |
67 |
Correct |
94 ms |
10324 KB |
Output is correct |
68 |
Correct |
66 ms |
10328 KB |
Output is correct |
69 |
Correct |
78 ms |
10224 KB |
Output is correct |
70 |
Correct |
61 ms |
10076 KB |
Output is correct |