# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991316 |
2024-06-02T01:05:32 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
103 ms |
12172 KB |
#include<bits/stdc++.h>
#include<ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define Fast ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define int long long
template<class T> using ordered_set = tree<T, null_type , less<T> ,rb_tree_tag , tree_order_statistics_node_update> ;
typedef long long ll;
const int N=3e5+3,LG=__lg(N)+2,M=21,MOD=998244353,inf=3e14;
pair<int,int> dp[2][N];
int v[N],n;
pair<int,int> sol(int mid) {
dp[0][0] = {0, 0};
dp[1][0] = {v[0] - mid, 1};
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 + v[i] - mid,
dp[0][i - 1].second + 1),
make_pair(dp[1][i - 1].first + v[i], dp[1][i - 1].second));
}
return max(dp[0][n - 1], dp[1][n - 1]);
}
void solve() {
int k;
cin>>n>>k;
for (int i = 0; i <n ; ++i)
cin>>v[i];
int l=0,r=inf;
while(r-l>1){
int mid=l+(r-l)/2;
if(sol(mid).second<k)
r=mid;
else l=mid;
}
cout<<sol(l).first+l*k<<'\n';
}
signed main() {
Fast;
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) {
// cout<<"Case #"<<i<<": ";
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
11856 KB |
Output is correct |
2 |
Correct |
47 ms |
12112 KB |
Output is correct |
3 |
Correct |
48 ms |
12172 KB |
Output is correct |
4 |
Correct |
47 ms |
12112 KB |
Output is correct |
5 |
Correct |
50 ms |
12124 KB |
Output is correct |
6 |
Correct |
45 ms |
11908 KB |
Output is correct |
7 |
Correct |
46 ms |
11856 KB |
Output is correct |
8 |
Correct |
47 ms |
12124 KB |
Output is correct |
9 |
Correct |
45 ms |
11868 KB |
Output is correct |
10 |
Correct |
46 ms |
11868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
11868 KB |
Output is correct |
2 |
Correct |
40 ms |
12124 KB |
Output is correct |
3 |
Correct |
39 ms |
12048 KB |
Output is correct |
4 |
Correct |
40 ms |
11868 KB |
Output is correct |
5 |
Correct |
45 ms |
11864 KB |
Output is correct |
6 |
Correct |
42 ms |
11868 KB |
Output is correct |
7 |
Correct |
40 ms |
12120 KB |
Output is correct |
8 |
Correct |
46 ms |
12124 KB |
Output is correct |
9 |
Correct |
47 ms |
11868 KB |
Output is correct |
10 |
Correct |
39 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
12124 KB |
Output is correct |
2 |
Correct |
68 ms |
11868 KB |
Output is correct |
3 |
Correct |
66 ms |
12124 KB |
Output is correct |
4 |
Correct |
69 ms |
11868 KB |
Output is correct |
5 |
Correct |
65 ms |
12112 KB |
Output is correct |
6 |
Correct |
66 ms |
12124 KB |
Output is correct |
7 |
Correct |
66 ms |
12120 KB |
Output is correct |
8 |
Correct |
65 ms |
12120 KB |
Output is correct |
9 |
Correct |
66 ms |
12124 KB |
Output is correct |
10 |
Correct |
67 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4580 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4580 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
11856 KB |
Output is correct |
2 |
Correct |
47 ms |
12112 KB |
Output is correct |
3 |
Correct |
48 ms |
12172 KB |
Output is correct |
4 |
Correct |
47 ms |
12112 KB |
Output is correct |
5 |
Correct |
50 ms |
12124 KB |
Output is correct |
6 |
Correct |
45 ms |
11908 KB |
Output is correct |
7 |
Correct |
46 ms |
11856 KB |
Output is correct |
8 |
Correct |
47 ms |
12124 KB |
Output is correct |
9 |
Correct |
45 ms |
11868 KB |
Output is correct |
10 |
Correct |
46 ms |
11868 KB |
Output is correct |
11 |
Correct |
40 ms |
11868 KB |
Output is correct |
12 |
Correct |
40 ms |
12124 KB |
Output is correct |
13 |
Correct |
39 ms |
12048 KB |
Output is correct |
14 |
Correct |
40 ms |
11868 KB |
Output is correct |
15 |
Correct |
45 ms |
11864 KB |
Output is correct |
16 |
Correct |
42 ms |
11868 KB |
Output is correct |
17 |
Correct |
40 ms |
12120 KB |
Output is correct |
18 |
Correct |
46 ms |
12124 KB |
Output is correct |
19 |
Correct |
47 ms |
11868 KB |
Output is correct |
20 |
Correct |
39 ms |
12120 KB |
Output is correct |
21 |
Correct |
67 ms |
12124 KB |
Output is correct |
22 |
Correct |
68 ms |
11868 KB |
Output is correct |
23 |
Correct |
66 ms |
12124 KB |
Output is correct |
24 |
Correct |
69 ms |
11868 KB |
Output is correct |
25 |
Correct |
65 ms |
12112 KB |
Output is correct |
26 |
Correct |
66 ms |
12124 KB |
Output is correct |
27 |
Correct |
66 ms |
12120 KB |
Output is correct |
28 |
Correct |
65 ms |
12120 KB |
Output is correct |
29 |
Correct |
66 ms |
12124 KB |
Output is correct |
30 |
Correct |
67 ms |
12120 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4440 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
0 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
1 ms |
4444 KB |
Output is correct |
47 |
Correct |
1 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4440 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4444 KB |
Output is correct |
55 |
Correct |
1 ms |
4444 KB |
Output is correct |
56 |
Correct |
2 ms |
4580 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
58 |
Correct |
1 ms |
4444 KB |
Output is correct |
59 |
Correct |
1 ms |
4580 KB |
Output is correct |
60 |
Correct |
1 ms |
4444 KB |
Output is correct |
61 |
Correct |
94 ms |
11868 KB |
Output is correct |
62 |
Correct |
97 ms |
12124 KB |
Output is correct |
63 |
Correct |
79 ms |
11868 KB |
Output is correct |
64 |
Correct |
96 ms |
12124 KB |
Output is correct |
65 |
Correct |
100 ms |
12116 KB |
Output is correct |
66 |
Correct |
103 ms |
12124 KB |
Output is correct |
67 |
Correct |
100 ms |
11856 KB |
Output is correct |
68 |
Correct |
68 ms |
11904 KB |
Output is correct |
69 |
Correct |
75 ms |
12048 KB |
Output is correct |
70 |
Correct |
65 ms |
11856 KB |
Output is correct |