# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1103167 |
2024-10-20T12:28:29 Z |
0pt1mus23 |
Feast (NOI19_feast) |
C++14 |
|
127 ms |
20048 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
// mt19937 rng(time(0));
const int mod = 1e9 +9, sze = 5e5 +23, inf = LLONG_MAX, LL = 30;
// Lagrangian Relaxation - Usaco Guide
pair<int,int> dp[2][sze];
int arr[sze];
int n;
void clc(int mid){
dp[1][0]={arr[0]-mid,1};
dp[0][0]={0,0};
for(int i=1;i<n;i++){
dp[0][i]=max(dp[0][i-1],dp[1][i-1]);
dp[1][i]=max(
make_pair(dp[0][i-1].first + arr[i]-mid,dp[0][i-1].second +1),
make_pair(dp[1][i-1].first + arr[i],dp[1][i-1].second)
);
}
}
void rush(){
int k;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>arr[i];
}
int l =0;
int r = 1e18;
int ans=0;
while(l<=r){
int mid = (l+r)/2;
clc(mid);
auto mx = max(dp[1][n-1],dp[0][n-1]);
if(mx.second >=k ){
ans=mid;
l=mid+1;
}
else{
r = mid-1;
}
}
clc(ans);
auto mx = max(dp[1][n-1],dp[0][n-1]);
putr( k*ans + mx.first );
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
rush();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
16968 KB |
Output is correct |
2 |
Correct |
55 ms |
17364 KB |
Output is correct |
3 |
Correct |
57 ms |
17304 KB |
Output is correct |
4 |
Correct |
54 ms |
17400 KB |
Output is correct |
5 |
Correct |
58 ms |
18432 KB |
Output is correct |
6 |
Correct |
52 ms |
16968 KB |
Output is correct |
7 |
Correct |
52 ms |
16976 KB |
Output is correct |
8 |
Correct |
52 ms |
16976 KB |
Output is correct |
9 |
Correct |
52 ms |
17024 KB |
Output is correct |
10 |
Correct |
62 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
16976 KB |
Output is correct |
2 |
Correct |
47 ms |
16976 KB |
Output is correct |
3 |
Correct |
52 ms |
16976 KB |
Output is correct |
4 |
Correct |
46 ms |
16976 KB |
Output is correct |
5 |
Correct |
55 ms |
18132 KB |
Output is correct |
6 |
Correct |
49 ms |
17084 KB |
Output is correct |
7 |
Correct |
47 ms |
17232 KB |
Output is correct |
8 |
Correct |
69 ms |
19188 KB |
Output is correct |
9 |
Correct |
55 ms |
16976 KB |
Output is correct |
10 |
Correct |
51 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
16976 KB |
Output is correct |
2 |
Correct |
96 ms |
17884 KB |
Output is correct |
3 |
Correct |
86 ms |
18400 KB |
Output is correct |
4 |
Correct |
95 ms |
18996 KB |
Output is correct |
5 |
Correct |
101 ms |
18504 KB |
Output is correct |
6 |
Correct |
82 ms |
16972 KB |
Output is correct |
7 |
Correct |
87 ms |
18388 KB |
Output is correct |
8 |
Correct |
84 ms |
18260 KB |
Output is correct |
9 |
Correct |
82 ms |
17228 KB |
Output is correct |
10 |
Correct |
87 ms |
19528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4664 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4604 KB |
Output is correct |
9 |
Correct |
1 ms |
4432 KB |
Output is correct |
10 |
Correct |
1 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4664 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4604 KB |
Output is correct |
9 |
Correct |
1 ms |
4432 KB |
Output is correct |
10 |
Correct |
1 ms |
4432 KB |
Output is correct |
11 |
Correct |
1 ms |
4432 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4432 KB |
Output is correct |
16 |
Correct |
1 ms |
4432 KB |
Output is correct |
17 |
Correct |
1 ms |
4432 KB |
Output is correct |
18 |
Correct |
1 ms |
4432 KB |
Output is correct |
19 |
Correct |
1 ms |
4432 KB |
Output is correct |
20 |
Correct |
1 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4664 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4604 KB |
Output is correct |
9 |
Correct |
1 ms |
4432 KB |
Output is correct |
10 |
Correct |
1 ms |
4432 KB |
Output is correct |
11 |
Correct |
1 ms |
4432 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4432 KB |
Output is correct |
16 |
Correct |
1 ms |
4432 KB |
Output is correct |
17 |
Correct |
1 ms |
4432 KB |
Output is correct |
18 |
Correct |
1 ms |
4432 KB |
Output is correct |
19 |
Correct |
1 ms |
4432 KB |
Output is correct |
20 |
Correct |
1 ms |
4432 KB |
Output is correct |
21 |
Correct |
2 ms |
4432 KB |
Output is correct |
22 |
Correct |
2 ms |
4432 KB |
Output is correct |
23 |
Correct |
2 ms |
4432 KB |
Output is correct |
24 |
Correct |
1 ms |
4432 KB |
Output is correct |
25 |
Correct |
2 ms |
4432 KB |
Output is correct |
26 |
Correct |
1 ms |
4432 KB |
Output is correct |
27 |
Correct |
1 ms |
4432 KB |
Output is correct |
28 |
Correct |
1 ms |
4432 KB |
Output is correct |
29 |
Correct |
2 ms |
4432 KB |
Output is correct |
30 |
Correct |
2 ms |
4532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
16968 KB |
Output is correct |
2 |
Correct |
55 ms |
17364 KB |
Output is correct |
3 |
Correct |
57 ms |
17304 KB |
Output is correct |
4 |
Correct |
54 ms |
17400 KB |
Output is correct |
5 |
Correct |
58 ms |
18432 KB |
Output is correct |
6 |
Correct |
52 ms |
16968 KB |
Output is correct |
7 |
Correct |
52 ms |
16976 KB |
Output is correct |
8 |
Correct |
52 ms |
16976 KB |
Output is correct |
9 |
Correct |
52 ms |
17024 KB |
Output is correct |
10 |
Correct |
62 ms |
16976 KB |
Output is correct |
11 |
Correct |
53 ms |
16976 KB |
Output is correct |
12 |
Correct |
47 ms |
16976 KB |
Output is correct |
13 |
Correct |
52 ms |
16976 KB |
Output is correct |
14 |
Correct |
46 ms |
16976 KB |
Output is correct |
15 |
Correct |
55 ms |
18132 KB |
Output is correct |
16 |
Correct |
49 ms |
17084 KB |
Output is correct |
17 |
Correct |
47 ms |
17232 KB |
Output is correct |
18 |
Correct |
69 ms |
19188 KB |
Output is correct |
19 |
Correct |
55 ms |
16976 KB |
Output is correct |
20 |
Correct |
51 ms |
16976 KB |
Output is correct |
21 |
Correct |
81 ms |
16976 KB |
Output is correct |
22 |
Correct |
96 ms |
17884 KB |
Output is correct |
23 |
Correct |
86 ms |
18400 KB |
Output is correct |
24 |
Correct |
95 ms |
18996 KB |
Output is correct |
25 |
Correct |
101 ms |
18504 KB |
Output is correct |
26 |
Correct |
82 ms |
16972 KB |
Output is correct |
27 |
Correct |
87 ms |
18388 KB |
Output is correct |
28 |
Correct |
84 ms |
18260 KB |
Output is correct |
29 |
Correct |
82 ms |
17228 KB |
Output is correct |
30 |
Correct |
87 ms |
19528 KB |
Output is correct |
31 |
Correct |
1 ms |
4432 KB |
Output is correct |
32 |
Correct |
1 ms |
4432 KB |
Output is correct |
33 |
Correct |
1 ms |
4560 KB |
Output is correct |
34 |
Correct |
1 ms |
4664 KB |
Output is correct |
35 |
Correct |
1 ms |
4432 KB |
Output is correct |
36 |
Correct |
1 ms |
4432 KB |
Output is correct |
37 |
Correct |
2 ms |
4432 KB |
Output is correct |
38 |
Correct |
1 ms |
4604 KB |
Output is correct |
39 |
Correct |
1 ms |
4432 KB |
Output is correct |
40 |
Correct |
1 ms |
4432 KB |
Output is correct |
41 |
Correct |
1 ms |
4432 KB |
Output is correct |
42 |
Correct |
2 ms |
4432 KB |
Output is correct |
43 |
Correct |
1 ms |
4432 KB |
Output is correct |
44 |
Correct |
1 ms |
4432 KB |
Output is correct |
45 |
Correct |
1 ms |
4432 KB |
Output is correct |
46 |
Correct |
1 ms |
4432 KB |
Output is correct |
47 |
Correct |
1 ms |
4432 KB |
Output is correct |
48 |
Correct |
1 ms |
4432 KB |
Output is correct |
49 |
Correct |
1 ms |
4432 KB |
Output is correct |
50 |
Correct |
1 ms |
4432 KB |
Output is correct |
51 |
Correct |
2 ms |
4432 KB |
Output is correct |
52 |
Correct |
2 ms |
4432 KB |
Output is correct |
53 |
Correct |
2 ms |
4432 KB |
Output is correct |
54 |
Correct |
1 ms |
4432 KB |
Output is correct |
55 |
Correct |
2 ms |
4432 KB |
Output is correct |
56 |
Correct |
1 ms |
4432 KB |
Output is correct |
57 |
Correct |
1 ms |
4432 KB |
Output is correct |
58 |
Correct |
1 ms |
4432 KB |
Output is correct |
59 |
Correct |
2 ms |
4432 KB |
Output is correct |
60 |
Correct |
2 ms |
4532 KB |
Output is correct |
61 |
Correct |
116 ms |
19788 KB |
Output is correct |
62 |
Correct |
124 ms |
20040 KB |
Output is correct |
63 |
Correct |
102 ms |
19792 KB |
Output is correct |
64 |
Correct |
120 ms |
20040 KB |
Output is correct |
65 |
Correct |
121 ms |
20048 KB |
Output is correct |
66 |
Correct |
127 ms |
20040 KB |
Output is correct |
67 |
Correct |
124 ms |
20040 KB |
Output is correct |
68 |
Correct |
85 ms |
20036 KB |
Output is correct |
69 |
Correct |
85 ms |
19784 KB |
Output is correct |
70 |
Correct |
83 ms |
18648 KB |
Output is correct |