# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017425 |
2024-07-09T07:53:48 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
138 ms |
14712 KB |
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define pll2 pair<pll,ll>
#define bit(i,k) ((k>>i)&1)
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const long long mod = 1e9+7;
const ll inf = 1e18;
const ll maxN = 3e5+5;
ll n,k;
ll a[maxN];
pll go(ll lambda){
pll dp[n+5][2]={};//lay i hoac deo
dp[0][1].ff=-inf;
for(int i=1;i<=n;i++){
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
pll p1={dp[i-1][0].ff+a[i]-lambda,dp[i-1][0].ss+1};
pll p2={dp[i-1][1].ff+a[i],dp[i-1][1].ss};
dp[i][1]=max(p1,p2);
}
return max(dp[n][1],dp[n][0]);
}
void solve() {
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
ll l=0,r=inf;
ll lmd;
ll ans=-inf;
while(l<r){
ll md=(l+r+1)/2;
pll p=go(md);
if(p.ss>=k){ans=p.ff;l=md;}
else{r=md-1;}
}
cout<<max(0ll,go(l).ff+k*l);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("rao.inp", "r", stdin);
// freopen("rao.out", "w", stdout);
ll nhim = 1;
// cin >> nhim;
// cout<<nhim<<'\n';
while (nhim--) {
solve();
}
}
Compilation message
feast.cpp: In function 'void solve()':
feast.cpp:42:6: warning: unused variable 'lmd' [-Wunused-variable]
42 | ll lmd;
| ^~~
feast.cpp:43:6: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
43 | ll ans=-inf;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
13904 KB |
Output is correct |
2 |
Correct |
71 ms |
14416 KB |
Output is correct |
3 |
Correct |
71 ms |
14608 KB |
Output is correct |
4 |
Correct |
69 ms |
14416 KB |
Output is correct |
5 |
Correct |
85 ms |
14456 KB |
Output is correct |
6 |
Correct |
75 ms |
14160 KB |
Output is correct |
7 |
Correct |
75 ms |
14016 KB |
Output is correct |
8 |
Correct |
80 ms |
14420 KB |
Output is correct |
9 |
Correct |
67 ms |
13904 KB |
Output is correct |
10 |
Correct |
74 ms |
14528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12892 KB |
Output is correct |
2 |
Correct |
64 ms |
13256 KB |
Output is correct |
3 |
Correct |
62 ms |
12836 KB |
Output is correct |
4 |
Correct |
61 ms |
13096 KB |
Output is correct |
5 |
Correct |
68 ms |
14144 KB |
Output is correct |
6 |
Correct |
61 ms |
12892 KB |
Output is correct |
7 |
Correct |
68 ms |
13308 KB |
Output is correct |
8 |
Correct |
76 ms |
14668 KB |
Output is correct |
9 |
Correct |
69 ms |
13904 KB |
Output is correct |
10 |
Correct |
75 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
14420 KB |
Output is correct |
2 |
Correct |
108 ms |
14428 KB |
Output is correct |
3 |
Correct |
95 ms |
14332 KB |
Output is correct |
4 |
Correct |
95 ms |
14260 KB |
Output is correct |
5 |
Correct |
101 ms |
14420 KB |
Output is correct |
6 |
Correct |
122 ms |
14528 KB |
Output is correct |
7 |
Correct |
96 ms |
14680 KB |
Output is correct |
8 |
Correct |
94 ms |
14420 KB |
Output is correct |
9 |
Correct |
93 ms |
14712 KB |
Output is correct |
10 |
Correct |
111 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
472 KB |
Output is correct |
19 |
Correct |
0 ms |
464 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
472 KB |
Output is correct |
19 |
Correct |
0 ms |
464 KB |
Output is correct |
20 |
Correct |
0 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 |
480 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 |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
508 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
13904 KB |
Output is correct |
2 |
Correct |
71 ms |
14416 KB |
Output is correct |
3 |
Correct |
71 ms |
14608 KB |
Output is correct |
4 |
Correct |
69 ms |
14416 KB |
Output is correct |
5 |
Correct |
85 ms |
14456 KB |
Output is correct |
6 |
Correct |
75 ms |
14160 KB |
Output is correct |
7 |
Correct |
75 ms |
14016 KB |
Output is correct |
8 |
Correct |
80 ms |
14420 KB |
Output is correct |
9 |
Correct |
67 ms |
13904 KB |
Output is correct |
10 |
Correct |
74 ms |
14528 KB |
Output is correct |
11 |
Correct |
65 ms |
12892 KB |
Output is correct |
12 |
Correct |
64 ms |
13256 KB |
Output is correct |
13 |
Correct |
62 ms |
12836 KB |
Output is correct |
14 |
Correct |
61 ms |
13096 KB |
Output is correct |
15 |
Correct |
68 ms |
14144 KB |
Output is correct |
16 |
Correct |
61 ms |
12892 KB |
Output is correct |
17 |
Correct |
68 ms |
13308 KB |
Output is correct |
18 |
Correct |
76 ms |
14668 KB |
Output is correct |
19 |
Correct |
69 ms |
13904 KB |
Output is correct |
20 |
Correct |
75 ms |
13140 KB |
Output is correct |
21 |
Correct |
98 ms |
14420 KB |
Output is correct |
22 |
Correct |
108 ms |
14428 KB |
Output is correct |
23 |
Correct |
95 ms |
14332 KB |
Output is correct |
24 |
Correct |
95 ms |
14260 KB |
Output is correct |
25 |
Correct |
101 ms |
14420 KB |
Output is correct |
26 |
Correct |
122 ms |
14528 KB |
Output is correct |
27 |
Correct |
96 ms |
14680 KB |
Output is correct |
28 |
Correct |
94 ms |
14420 KB |
Output is correct |
29 |
Correct |
93 ms |
14712 KB |
Output is correct |
30 |
Correct |
111 ms |
14676 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
464 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
472 KB |
Output is correct |
49 |
Correct |
0 ms |
464 KB |
Output is correct |
50 |
Correct |
0 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 |
480 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 |
344 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
508 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
126 ms |
14240 KB |
Output is correct |
62 |
Correct |
124 ms |
14676 KB |
Output is correct |
63 |
Correct |
110 ms |
14400 KB |
Output is correct |
64 |
Correct |
134 ms |
14644 KB |
Output is correct |
65 |
Correct |
138 ms |
14596 KB |
Output is correct |
66 |
Correct |
129 ms |
14604 KB |
Output is correct |
67 |
Correct |
135 ms |
14420 KB |
Output is correct |
68 |
Correct |
110 ms |
14416 KB |
Output is correct |
69 |
Correct |
99 ms |
14416 KB |
Output is correct |
70 |
Correct |
94 ms |
14160 KB |
Output is correct |