# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1116469 |
2024-11-21T16:56:48 Z |
manizare |
Feast (NOI19_feast) |
C++14 |
|
120 ms |
13896 KB |
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define S second
#define sz(a) (int)a.size()
#define rep(i , a , b) for(int i = (a) ; i <= (b) ; i++)
#define per(i , a , b) for(int i = (a) ; i >= (b) ; i--)
#define int long long
using namespace std ;
const int maxn = 3e5 + 10 , mod = 1e9 + 7 , inf = 1e18 ;
pii dp[maxn][2] ;
int a[maxn] , n , k ;
void mx(pii &a , pii b){
if(a.F < b.F || (a.F==b.F && a.S < b.S))a = b;
}
pii ch(int x){
dp[0][0] = {0 ,0};
dp[0][1] = {-inf , 0} ;
rep(i ,1, n){
dp[i][0] = dp[i-1][0] ;
mx(dp[i][0] , dp[i-1][1]) ;
dp[i][1] = {dp[i-1][1].F+a[i] , dp[i-1][1].S};
mx(dp[i][1] , {dp[i-1][0].F+a[i]-x , dp[i-1][0].S+1}) ;
}
pii ans = dp[n][0] ;
mx(ans , dp[n][1]);
return ans ;
}
signed main(){
ios_base::sync_with_stdio(false) ; cin.tie(0) ;
cin >> n >> k;
rep(i ,1, n){
cin >> a[i] ;
}
int l = 0 , r= 1e18 ;
while(r-l>1) {
int mid = (l+r)/2 ;
if(ch(mid).S >= k){
l = mid ;
}else{
r = mid ;
}
}
cout << ch(l).F + l*k << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12360 KB |
Output is correct |
2 |
Correct |
59 ms |
12616 KB |
Output is correct |
3 |
Correct |
57 ms |
12112 KB |
Output is correct |
4 |
Correct |
61 ms |
13704 KB |
Output is correct |
5 |
Correct |
62 ms |
12620 KB |
Output is correct |
6 |
Correct |
62 ms |
13412 KB |
Output is correct |
7 |
Correct |
61 ms |
13368 KB |
Output is correct |
8 |
Correct |
60 ms |
12724 KB |
Output is correct |
9 |
Correct |
60 ms |
11856 KB |
Output is correct |
10 |
Correct |
57 ms |
11856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
11856 KB |
Output is correct |
2 |
Correct |
48 ms |
12680 KB |
Output is correct |
3 |
Correct |
54 ms |
12104 KB |
Output is correct |
4 |
Correct |
49 ms |
12024 KB |
Output is correct |
5 |
Correct |
53 ms |
13652 KB |
Output is correct |
6 |
Correct |
45 ms |
12112 KB |
Output is correct |
7 |
Correct |
50 ms |
12112 KB |
Output is correct |
8 |
Correct |
55 ms |
12132 KB |
Output is correct |
9 |
Correct |
56 ms |
13640 KB |
Output is correct |
10 |
Correct |
55 ms |
12896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
11856 KB |
Output is correct |
2 |
Correct |
85 ms |
12616 KB |
Output is correct |
3 |
Correct |
81 ms |
12616 KB |
Output is correct |
4 |
Correct |
85 ms |
12712 KB |
Output is correct |
5 |
Correct |
81 ms |
12748 KB |
Output is correct |
6 |
Correct |
84 ms |
13876 KB |
Output is correct |
7 |
Correct |
76 ms |
12112 KB |
Output is correct |
8 |
Correct |
81 ms |
13612 KB |
Output is correct |
9 |
Correct |
90 ms |
13860 KB |
Output is correct |
10 |
Correct |
82 ms |
13896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2552 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2552 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2516 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2552 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2516 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2556 KB |
Output is correct |
22 |
Correct |
1 ms |
2548 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
2 ms |
2384 KB |
Output is correct |
25 |
Correct |
2 ms |
2384 KB |
Output is correct |
26 |
Correct |
2 ms |
2384 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2552 KB |
Output is correct |
30 |
Correct |
2 ms |
2556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12360 KB |
Output is correct |
2 |
Correct |
59 ms |
12616 KB |
Output is correct |
3 |
Correct |
57 ms |
12112 KB |
Output is correct |
4 |
Correct |
61 ms |
13704 KB |
Output is correct |
5 |
Correct |
62 ms |
12620 KB |
Output is correct |
6 |
Correct |
62 ms |
13412 KB |
Output is correct |
7 |
Correct |
61 ms |
13368 KB |
Output is correct |
8 |
Correct |
60 ms |
12724 KB |
Output is correct |
9 |
Correct |
60 ms |
11856 KB |
Output is correct |
10 |
Correct |
57 ms |
11856 KB |
Output is correct |
11 |
Correct |
57 ms |
11856 KB |
Output is correct |
12 |
Correct |
48 ms |
12680 KB |
Output is correct |
13 |
Correct |
54 ms |
12104 KB |
Output is correct |
14 |
Correct |
49 ms |
12024 KB |
Output is correct |
15 |
Correct |
53 ms |
13652 KB |
Output is correct |
16 |
Correct |
45 ms |
12112 KB |
Output is correct |
17 |
Correct |
50 ms |
12112 KB |
Output is correct |
18 |
Correct |
55 ms |
12132 KB |
Output is correct |
19 |
Correct |
56 ms |
13640 KB |
Output is correct |
20 |
Correct |
55 ms |
12896 KB |
Output is correct |
21 |
Correct |
81 ms |
11856 KB |
Output is correct |
22 |
Correct |
85 ms |
12616 KB |
Output is correct |
23 |
Correct |
81 ms |
12616 KB |
Output is correct |
24 |
Correct |
85 ms |
12712 KB |
Output is correct |
25 |
Correct |
81 ms |
12748 KB |
Output is correct |
26 |
Correct |
84 ms |
13876 KB |
Output is correct |
27 |
Correct |
76 ms |
12112 KB |
Output is correct |
28 |
Correct |
81 ms |
13612 KB |
Output is correct |
29 |
Correct |
90 ms |
13860 KB |
Output is correct |
30 |
Correct |
82 ms |
13896 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2384 KB |
Output is correct |
34 |
Correct |
1 ms |
2552 KB |
Output is correct |
35 |
Correct |
1 ms |
2384 KB |
Output is correct |
36 |
Correct |
1 ms |
2384 KB |
Output is correct |
37 |
Correct |
1 ms |
2384 KB |
Output is correct |
38 |
Correct |
1 ms |
2384 KB |
Output is correct |
39 |
Correct |
1 ms |
2384 KB |
Output is correct |
40 |
Correct |
1 ms |
2384 KB |
Output is correct |
41 |
Correct |
1 ms |
2384 KB |
Output is correct |
42 |
Correct |
1 ms |
2384 KB |
Output is correct |
43 |
Correct |
1 ms |
2384 KB |
Output is correct |
44 |
Correct |
1 ms |
2384 KB |
Output is correct |
45 |
Correct |
1 ms |
2384 KB |
Output is correct |
46 |
Correct |
1 ms |
2384 KB |
Output is correct |
47 |
Correct |
1 ms |
2516 KB |
Output is correct |
48 |
Correct |
1 ms |
2384 KB |
Output is correct |
49 |
Correct |
1 ms |
2384 KB |
Output is correct |
50 |
Correct |
1 ms |
2384 KB |
Output is correct |
51 |
Correct |
2 ms |
2556 KB |
Output is correct |
52 |
Correct |
1 ms |
2548 KB |
Output is correct |
53 |
Correct |
1 ms |
2384 KB |
Output is correct |
54 |
Correct |
2 ms |
2384 KB |
Output is correct |
55 |
Correct |
2 ms |
2384 KB |
Output is correct |
56 |
Correct |
2 ms |
2384 KB |
Output is correct |
57 |
Correct |
1 ms |
2384 KB |
Output is correct |
58 |
Correct |
1 ms |
2384 KB |
Output is correct |
59 |
Correct |
1 ms |
2552 KB |
Output is correct |
60 |
Correct |
2 ms |
2556 KB |
Output is correct |
61 |
Correct |
120 ms |
13516 KB |
Output is correct |
62 |
Correct |
114 ms |
12964 KB |
Output is correct |
63 |
Correct |
94 ms |
12616 KB |
Output is correct |
64 |
Correct |
120 ms |
12872 KB |
Output is correct |
65 |
Correct |
113 ms |
12108 KB |
Output is correct |
66 |
Correct |
117 ms |
12872 KB |
Output is correct |
67 |
Correct |
118 ms |
11856 KB |
Output is correct |
68 |
Correct |
93 ms |
11904 KB |
Output is correct |
69 |
Correct |
84 ms |
11856 KB |
Output is correct |
70 |
Correct |
86 ms |
13640 KB |
Output is correct |