#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LL_MAX LONG_LONG_MAX
#define LL_MIN LONG_LONG_MIN
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ii> vii;
typedef set<ii> sii;
#define REP(i, a, b) for(int i = a; i < b; i++)
int32_t main() {
int N, K; cin >> N >> K; int A[N+1]; A[0]=0;
REP(i,1,N+1) {
cin>>A[i];
A[i]+=A[i-1];
//cerr<<i<<" "<<A[i]<<"\n";
}
ii dp[N+1];
int l = -1, h = 300000000000005;
while(h-l>1){
dp[0]=mp(0,0);
int lambda = (l+h)/2;
//printf("Attempting lambda=%lld\n",lambda);
ii best = mp(0,0); // value, -1 * subarrs
REP(i,1,N+1) {
//printf("%lld %lld %lld\n",A[i],best.fi,lambda);
dp[i]=max(dp[i-1],mp(A[i]+best.fi-lambda,best.se-1));
//printf("dp[%lld] has value %lld and %lld subarrs\n",i,dp[i].fi,dp[i].se);
//printf("dp[%lld] has value %lld and %lld subarrs\n",i,dp[i].fi,dp[i].se);
stMx(best,mp(dp[i].fi-A[i],dp[i].se));
//printf("best is now %lld %lld\n",best.fi,best.se);
}
if(dp[N].se>=-1*K) h=lambda;
else l=lambda;
//REP(i,1,N+1){
// cerr<<i<<" "<<A[i]<<"\n";
//}
}
ii best = mp(0,0); // value, -1 * subarrs
REP(i,1,N+1) {
//printf("%lld %lld %lld\n",A[i],best.fi,lambda);
dp[i]=max(dp[i-1],mp(A[i]+best.fi-h,best.se-1));
//printf("dp[%lld] has value %lld and %lld subarrs\n",i,dp[i].fi,dp[i].se);
//printf("dp[%lld] has value %lld and %lld subarrs\n",i,dp[i].fi,dp[i].se);
stMx(best,mp(dp[i].fi-A[i],dp[i].se));
//printf("best is now %lld %lld\n",best.fi,best.se);
}
cout << dp[N].fi+h*K;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
6988 KB |
Output is correct |
2 |
Correct |
132 ms |
7196 KB |
Output is correct |
3 |
Correct |
135 ms |
7240 KB |
Output is correct |
4 |
Correct |
145 ms |
7332 KB |
Output is correct |
5 |
Correct |
129 ms |
7196 KB |
Output is correct |
6 |
Correct |
128 ms |
9804 KB |
Output is correct |
7 |
Correct |
137 ms |
9900 KB |
Output is correct |
8 |
Correct |
139 ms |
10004 KB |
Output is correct |
9 |
Correct |
134 ms |
9936 KB |
Output is correct |
10 |
Correct |
130 ms |
9988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
7144 KB |
Output is correct |
2 |
Correct |
96 ms |
8360 KB |
Output is correct |
3 |
Correct |
86 ms |
8140 KB |
Output is correct |
4 |
Correct |
88 ms |
8324 KB |
Output is correct |
5 |
Correct |
135 ms |
9836 KB |
Output is correct |
6 |
Correct |
90 ms |
8184 KB |
Output is correct |
7 |
Correct |
90 ms |
8372 KB |
Output is correct |
8 |
Correct |
133 ms |
10148 KB |
Output is correct |
9 |
Correct |
128 ms |
9816 KB |
Output is correct |
10 |
Correct |
89 ms |
8396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
7240 KB |
Output is correct |
2 |
Correct |
173 ms |
7040 KB |
Output is correct |
3 |
Correct |
186 ms |
10124 KB |
Output is correct |
4 |
Correct |
175 ms |
10060 KB |
Output is correct |
5 |
Correct |
170 ms |
10136 KB |
Output is correct |
6 |
Correct |
171 ms |
10316 KB |
Output is correct |
7 |
Correct |
198 ms |
10332 KB |
Output is correct |
8 |
Correct |
164 ms |
10140 KB |
Output is correct |
9 |
Correct |
180 ms |
10284 KB |
Output is correct |
10 |
Correct |
199 ms |
10444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
316 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
312 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
328 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
6988 KB |
Output is correct |
2 |
Correct |
132 ms |
7196 KB |
Output is correct |
3 |
Correct |
135 ms |
7240 KB |
Output is correct |
4 |
Correct |
145 ms |
7332 KB |
Output is correct |
5 |
Correct |
129 ms |
7196 KB |
Output is correct |
6 |
Correct |
128 ms |
9804 KB |
Output is correct |
7 |
Correct |
137 ms |
9900 KB |
Output is correct |
8 |
Correct |
139 ms |
10004 KB |
Output is correct |
9 |
Correct |
134 ms |
9936 KB |
Output is correct |
10 |
Correct |
130 ms |
9988 KB |
Output is correct |
11 |
Correct |
123 ms |
7144 KB |
Output is correct |
12 |
Correct |
96 ms |
8360 KB |
Output is correct |
13 |
Correct |
86 ms |
8140 KB |
Output is correct |
14 |
Correct |
88 ms |
8324 KB |
Output is correct |
15 |
Correct |
135 ms |
9836 KB |
Output is correct |
16 |
Correct |
90 ms |
8184 KB |
Output is correct |
17 |
Correct |
90 ms |
8372 KB |
Output is correct |
18 |
Correct |
133 ms |
10148 KB |
Output is correct |
19 |
Correct |
128 ms |
9816 KB |
Output is correct |
20 |
Correct |
89 ms |
8396 KB |
Output is correct |
21 |
Correct |
161 ms |
7240 KB |
Output is correct |
22 |
Correct |
173 ms |
7040 KB |
Output is correct |
23 |
Correct |
186 ms |
10124 KB |
Output is correct |
24 |
Correct |
175 ms |
10060 KB |
Output is correct |
25 |
Correct |
170 ms |
10136 KB |
Output is correct |
26 |
Correct |
171 ms |
10316 KB |
Output is correct |
27 |
Correct |
198 ms |
10332 KB |
Output is correct |
28 |
Correct |
164 ms |
10140 KB |
Output is correct |
29 |
Correct |
180 ms |
10284 KB |
Output is correct |
30 |
Correct |
199 ms |
10444 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
296 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
304 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
304 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
2 ms |
316 KB |
Output is correct |
52 |
Correct |
2 ms |
340 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
2 ms |
312 KB |
Output is correct |
55 |
Correct |
2 ms |
332 KB |
Output is correct |
56 |
Correct |
2 ms |
340 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
328 KB |
Output is correct |
59 |
Correct |
2 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
308 KB |
Output is correct |
61 |
Correct |
196 ms |
10104 KB |
Output is correct |
62 |
Correct |
200 ms |
10380 KB |
Output is correct |
63 |
Correct |
227 ms |
10092 KB |
Output is correct |
64 |
Correct |
198 ms |
10292 KB |
Output is correct |
65 |
Correct |
205 ms |
10288 KB |
Output is correct |
66 |
Correct |
229 ms |
10256 KB |
Output is correct |
67 |
Correct |
198 ms |
10088 KB |
Output is correct |
68 |
Correct |
172 ms |
10268 KB |
Output is correct |
69 |
Correct |
192 ms |
10092 KB |
Output is correct |
70 |
Correct |
170 ms |
9952 KB |
Output is correct |