#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
int n,k;
vector<int> vect1;
pair<int,int> find(int val){
vector<int> dp(n,0);
vector<int> take(n,0);
int currmin = 0;
int currtake = 0;
for(int i=0;i<n;i++){
if(i!=0){
dp[i] = dp[i-1];
take[i] = take[i-1];
}
if(vect1[i]-currmin-val>dp[i]){
dp[i] = vect1[i]-currmin-val;
take[i] = currtake+1;
}
if(vect1[i]-dp[i]<currmin){
currmin = vect1[i]-dp[i];
currtake = take[i];
}
}
return {dp[n-1],take[n-1]};
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> k;
int input;
for(int i=0;i<n;i++){
cin >> input;
vect1.push_back(input);
}
for(int i=1;i<n;i++){
vect1[i] += vect1[i-1];
}
int lo = 0,hi = 10e15;
while(lo+1!=hi){
int mid = (lo+hi)/2;
if(find(mid).s>=k){
lo = mid;
}
else{
hi = mid;
}
}
//cout << lo << " " << hi << endl;
cout << find(lo).f+lo*k;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
10220 KB |
Output is correct |
2 |
Correct |
202 ms |
10336 KB |
Output is correct |
3 |
Correct |
207 ms |
10508 KB |
Output is correct |
4 |
Correct |
211 ms |
10416 KB |
Output is correct |
5 |
Correct |
230 ms |
10336 KB |
Output is correct |
6 |
Correct |
199 ms |
10252 KB |
Output is correct |
7 |
Correct |
207 ms |
10304 KB |
Output is correct |
8 |
Correct |
216 ms |
10420 KB |
Output is correct |
9 |
Correct |
204 ms |
10256 KB |
Output is correct |
10 |
Correct |
212 ms |
10316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
8544 KB |
Output is correct |
2 |
Correct |
200 ms |
8672 KB |
Output is correct |
3 |
Correct |
198 ms |
8524 KB |
Output is correct |
4 |
Correct |
194 ms |
8544 KB |
Output is correct |
5 |
Correct |
212 ms |
10272 KB |
Output is correct |
6 |
Correct |
226 ms |
8608 KB |
Output is correct |
7 |
Correct |
199 ms |
8728 KB |
Output is correct |
8 |
Correct |
218 ms |
10436 KB |
Output is correct |
9 |
Correct |
217 ms |
10240 KB |
Output is correct |
10 |
Correct |
199 ms |
8688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
229 ms |
10464 KB |
Output is correct |
2 |
Correct |
259 ms |
10440 KB |
Output is correct |
3 |
Correct |
234 ms |
10556 KB |
Output is correct |
4 |
Correct |
245 ms |
10608 KB |
Output is correct |
5 |
Correct |
230 ms |
10464 KB |
Output is correct |
6 |
Correct |
237 ms |
10692 KB |
Output is correct |
7 |
Correct |
234 ms |
10696 KB |
Output is correct |
8 |
Correct |
229 ms |
10652 KB |
Output is correct |
9 |
Correct |
259 ms |
10748 KB |
Output is correct |
10 |
Correct |
235 ms |
10592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
10220 KB |
Output is correct |
2 |
Correct |
202 ms |
10336 KB |
Output is correct |
3 |
Correct |
207 ms |
10508 KB |
Output is correct |
4 |
Correct |
211 ms |
10416 KB |
Output is correct |
5 |
Correct |
230 ms |
10336 KB |
Output is correct |
6 |
Correct |
199 ms |
10252 KB |
Output is correct |
7 |
Correct |
207 ms |
10304 KB |
Output is correct |
8 |
Correct |
216 ms |
10420 KB |
Output is correct |
9 |
Correct |
204 ms |
10256 KB |
Output is correct |
10 |
Correct |
212 ms |
10316 KB |
Output is correct |
11 |
Correct |
194 ms |
8544 KB |
Output is correct |
12 |
Correct |
200 ms |
8672 KB |
Output is correct |
13 |
Correct |
198 ms |
8524 KB |
Output is correct |
14 |
Correct |
194 ms |
8544 KB |
Output is correct |
15 |
Correct |
212 ms |
10272 KB |
Output is correct |
16 |
Correct |
226 ms |
8608 KB |
Output is correct |
17 |
Correct |
199 ms |
8728 KB |
Output is correct |
18 |
Correct |
218 ms |
10436 KB |
Output is correct |
19 |
Correct |
217 ms |
10240 KB |
Output is correct |
20 |
Correct |
199 ms |
8688 KB |
Output is correct |
21 |
Correct |
229 ms |
10464 KB |
Output is correct |
22 |
Correct |
259 ms |
10440 KB |
Output is correct |
23 |
Correct |
234 ms |
10556 KB |
Output is correct |
24 |
Correct |
245 ms |
10608 KB |
Output is correct |
25 |
Correct |
230 ms |
10464 KB |
Output is correct |
26 |
Correct |
237 ms |
10692 KB |
Output is correct |
27 |
Correct |
234 ms |
10696 KB |
Output is correct |
28 |
Correct |
229 ms |
10652 KB |
Output is correct |
29 |
Correct |
259 ms |
10748 KB |
Output is correct |
30 |
Correct |
235 ms |
10592 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
364 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
1 ms |
364 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
2 ms |
364 KB |
Output is correct |
52 |
Correct |
1 ms |
364 KB |
Output is correct |
53 |
Correct |
1 ms |
364 KB |
Output is correct |
54 |
Correct |
1 ms |
364 KB |
Output is correct |
55 |
Correct |
2 ms |
364 KB |
Output is correct |
56 |
Correct |
1 ms |
364 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
266 ms |
10464 KB |
Output is correct |
62 |
Correct |
280 ms |
10756 KB |
Output is correct |
63 |
Correct |
246 ms |
10396 KB |
Output is correct |
64 |
Correct |
274 ms |
10596 KB |
Output is correct |
65 |
Correct |
281 ms |
10572 KB |
Output is correct |
66 |
Correct |
277 ms |
10584 KB |
Output is correct |
67 |
Correct |
265 ms |
10524 KB |
Output is correct |
68 |
Correct |
245 ms |
10516 KB |
Output is correct |
69 |
Correct |
261 ms |
10360 KB |
Output is correct |
70 |
Correct |
231 ms |
10388 KB |
Output is correct |