# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017648 |
2024-07-09T09:19:27 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
216 ms |
2924 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pii pair<ll,ll>
const int mxN = 3e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
bool operator>(pair<ll,int> a,pair<ll,int>b){
return make_pair(a.F,-1 * a.S) > make_pair(b.F, -1 * b.S);
}
bool operator<(pair<ll,int> a,pair<ll,int>b){
return make_pair(a.F,-1 * a.S) < make_pair(b.F, -1 * b.S);
}
int n,k;
ll a[mxN];
pair<ll,int> dp[2][2];
pair<ll,int> num;
ll ans;
bool solve(ll lam){
// cout<<lam<<'\n';
for(int i = 0;i <= 1;i++){
dp[i][0] = make_pair(0,0);
dp[i][1] = make_pair(0,0);
}
for(int i = 1;i <= n;i++){
// cout<<(i & 1)<<' '<<(~i & 1)<<'\n';
dp[(i & 1)][0] = max(dp[(~i & 1)][0],dp[(~i & 1)][1]);
dp[(i & 1)][1] = make_pair(dp[(~i & 1)][0].F + a[i] - lam,dp[~i & 1][0].S + 1);
if(i > 1) dp[(i & 1)][1] = max(dp[(i & 1)][1],make_pair(dp[~i & 1][1].F + a[i],dp[~i & 1][1].S));
// cout<<dp[(i & 1)][0].F<<' '<<dp[(i & 1)][0].S<<' '<<dp[(i & 1)][1].F<<' '<<dp[(i & 1)][1].S<<'\n';
}
num = max(dp[n & 1][0],dp[n & 1][1]);
// cout<<num.F<<' '<<num.S<<'\n';
return (num.S <= k);
}
signed main(){
// cout<<"TEST";
cin >>n>>k;
for(int i = 1;i <= n;i++) cin >>a[i];
ll l = 0,r = 1e16,md;
while(l < r){
md = (l + r) / 2;
if(solve(md)){
r = md;
ans = num.F + num.S * md;
}else l = md + 1;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
2640 KB |
Output is correct |
2 |
Correct |
118 ms |
2492 KB |
Output is correct |
3 |
Correct |
120 ms |
2640 KB |
Output is correct |
4 |
Correct |
118 ms |
2640 KB |
Output is correct |
5 |
Correct |
118 ms |
2716 KB |
Output is correct |
6 |
Correct |
117 ms |
2644 KB |
Output is correct |
7 |
Correct |
116 ms |
2644 KB |
Output is correct |
8 |
Correct |
120 ms |
2728 KB |
Output is correct |
9 |
Correct |
116 ms |
2604 KB |
Output is correct |
10 |
Correct |
122 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
2624 KB |
Output is correct |
2 |
Correct |
84 ms |
2640 KB |
Output is correct |
3 |
Correct |
90 ms |
2640 KB |
Output is correct |
4 |
Correct |
86 ms |
2700 KB |
Output is correct |
5 |
Correct |
127 ms |
2496 KB |
Output is correct |
6 |
Correct |
85 ms |
2924 KB |
Output is correct |
7 |
Correct |
86 ms |
2640 KB |
Output is correct |
8 |
Correct |
132 ms |
2640 KB |
Output is correct |
9 |
Correct |
115 ms |
2524 KB |
Output is correct |
10 |
Correct |
84 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
2644 KB |
Output is correct |
2 |
Correct |
147 ms |
2628 KB |
Output is correct |
3 |
Correct |
152 ms |
2544 KB |
Output is correct |
4 |
Correct |
149 ms |
2900 KB |
Output is correct |
5 |
Correct |
150 ms |
2640 KB |
Output is correct |
6 |
Correct |
150 ms |
2716 KB |
Output is correct |
7 |
Correct |
149 ms |
2572 KB |
Output is correct |
8 |
Correct |
162 ms |
2640 KB |
Output is correct |
9 |
Correct |
150 ms |
2644 KB |
Output is correct |
10 |
Correct |
167 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
2640 KB |
Output is correct |
2 |
Correct |
118 ms |
2492 KB |
Output is correct |
3 |
Correct |
120 ms |
2640 KB |
Output is correct |
4 |
Correct |
118 ms |
2640 KB |
Output is correct |
5 |
Correct |
118 ms |
2716 KB |
Output is correct |
6 |
Correct |
117 ms |
2644 KB |
Output is correct |
7 |
Correct |
116 ms |
2644 KB |
Output is correct |
8 |
Correct |
120 ms |
2728 KB |
Output is correct |
9 |
Correct |
116 ms |
2604 KB |
Output is correct |
10 |
Correct |
122 ms |
2644 KB |
Output is correct |
11 |
Correct |
83 ms |
2624 KB |
Output is correct |
12 |
Correct |
84 ms |
2640 KB |
Output is correct |
13 |
Correct |
90 ms |
2640 KB |
Output is correct |
14 |
Correct |
86 ms |
2700 KB |
Output is correct |
15 |
Correct |
127 ms |
2496 KB |
Output is correct |
16 |
Correct |
85 ms |
2924 KB |
Output is correct |
17 |
Correct |
86 ms |
2640 KB |
Output is correct |
18 |
Correct |
132 ms |
2640 KB |
Output is correct |
19 |
Correct |
115 ms |
2524 KB |
Output is correct |
20 |
Correct |
84 ms |
2644 KB |
Output is correct |
21 |
Correct |
148 ms |
2644 KB |
Output is correct |
22 |
Correct |
147 ms |
2628 KB |
Output is correct |
23 |
Correct |
152 ms |
2544 KB |
Output is correct |
24 |
Correct |
149 ms |
2900 KB |
Output is correct |
25 |
Correct |
150 ms |
2640 KB |
Output is correct |
26 |
Correct |
150 ms |
2716 KB |
Output is correct |
27 |
Correct |
149 ms |
2572 KB |
Output is correct |
28 |
Correct |
162 ms |
2640 KB |
Output is correct |
29 |
Correct |
150 ms |
2644 KB |
Output is correct |
30 |
Correct |
167 ms |
2644 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
364 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
174 ms |
2552 KB |
Output is correct |
62 |
Correct |
174 ms |
2644 KB |
Output is correct |
63 |
Correct |
160 ms |
2640 KB |
Output is correct |
64 |
Correct |
180 ms |
2500 KB |
Output is correct |
65 |
Correct |
188 ms |
2572 KB |
Output is correct |
66 |
Correct |
216 ms |
2716 KB |
Output is correct |
67 |
Correct |
181 ms |
2640 KB |
Output is correct |
68 |
Correct |
155 ms |
2644 KB |
Output is correct |
69 |
Correct |
149 ms |
2644 KB |
Output is correct |
70 |
Correct |
150 ms |
2640 KB |
Output is correct |