# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1112260 |
2024-11-13T23:07:26 Z |
tfgs |
Feast (NOI19_feast) |
C++17 |
|
165 ms |
5736 KB |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int inf=1e18;
#ifdef LOCAL
#include "algo/debug.h"
#endif
#define f first
#define s second
template<class T> using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using vs = V<string>;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define len(x) (int)((x).size())
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T> int lwb(V<T>& a, const T& b) { return lb(all(a),b)-begin(a); }
template<class T> int upb(V<T>& a, const T& b) { return ub(all(a),b)-begin(a); }
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a=b, true : false; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a=b, true : false; }
#define pct __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
constexpr int p2(int x) { return (int)1 << x; }
constexpr int bits(int x) { return x == 0 ? 0 : 31-clz(x); } // floor(log2(x))
template<class T>void UNIQUE(V<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); }
template<class T,class U>void erase(T& t, const U& u) { auto it = t.find(u); assert(it != end(t)); t.erase(it); }
array<int,2> operator+(const array<int,2>& a,const array<int,2>&b){
return {a[0]+b[0],a[1]+b[1]};
}
int n;
vi a;
array<int,2> calc_dp(int lambda){
array<array<int,2>,2>dp;
dp[0]={0,0};
dp[1]={-inf,69};
for(int i=0;i<n;i++){
//continue the last segment
dp[1][0]+=a[i];
//start a new segment
ckmax(dp[1],dp[0]+array<int,2>{a[i]-lambda,1});
//already no segment
//end the segment
ckmax(dp[0],dp[1]);
}
auto score=max(dp[0],dp[1]);
return score;
}
void solve() {
int k;cin>>n>>k;
a.rsz(n);
for(int&i:a)cin>>i;
int lo=0,hi=inf;
while(hi-lo>1){
int lambda=(lo+hi)/2;
//regular dp
//dp(i,0)=score if we've considered first i elts assuming:
//0: we don't take the i-th elt
//1: we take the ith elt
//
//score is (sum,+groups)
calc_dp(lambda)[1]>=k?lo=lambda:hi=lambda;
}
cout<<calc_dp(lo)[0]+k*lo<<'\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
5456 KB |
Output is correct |
2 |
Correct |
165 ms |
5456 KB |
Output is correct |
3 |
Correct |
154 ms |
5456 KB |
Output is correct |
4 |
Correct |
156 ms |
5456 KB |
Output is correct |
5 |
Correct |
153 ms |
5456 KB |
Output is correct |
6 |
Correct |
151 ms |
5448 KB |
Output is correct |
7 |
Correct |
150 ms |
5200 KB |
Output is correct |
8 |
Correct |
156 ms |
5448 KB |
Output is correct |
9 |
Correct |
150 ms |
5456 KB |
Output is correct |
10 |
Correct |
156 ms |
5448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3664 KB |
Output is correct |
2 |
Correct |
40 ms |
3920 KB |
Output is correct |
3 |
Correct |
37 ms |
3408 KB |
Output is correct |
4 |
Correct |
100 ms |
3664 KB |
Output is correct |
5 |
Correct |
50 ms |
5452 KB |
Output is correct |
6 |
Correct |
40 ms |
3820 KB |
Output is correct |
7 |
Correct |
99 ms |
3920 KB |
Output is correct |
8 |
Correct |
47 ms |
5456 KB |
Output is correct |
9 |
Correct |
49 ms |
5272 KB |
Output is correct |
10 |
Correct |
97 ms |
3920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
5712 KB |
Output is correct |
2 |
Correct |
69 ms |
4424 KB |
Output is correct |
3 |
Correct |
81 ms |
5564 KB |
Output is correct |
4 |
Correct |
65 ms |
4680 KB |
Output is correct |
5 |
Correct |
65 ms |
4688 KB |
Output is correct |
6 |
Correct |
65 ms |
5712 KB |
Output is correct |
7 |
Correct |
73 ms |
5484 KB |
Output is correct |
8 |
Correct |
76 ms |
5568 KB |
Output is correct |
9 |
Correct |
71 ms |
5712 KB |
Output is correct |
10 |
Correct |
70 ms |
4424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
476 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
5456 KB |
Output is correct |
2 |
Correct |
165 ms |
5456 KB |
Output is correct |
3 |
Correct |
154 ms |
5456 KB |
Output is correct |
4 |
Correct |
156 ms |
5456 KB |
Output is correct |
5 |
Correct |
153 ms |
5456 KB |
Output is correct |
6 |
Correct |
151 ms |
5448 KB |
Output is correct |
7 |
Correct |
150 ms |
5200 KB |
Output is correct |
8 |
Correct |
156 ms |
5448 KB |
Output is correct |
9 |
Correct |
150 ms |
5456 KB |
Output is correct |
10 |
Correct |
156 ms |
5448 KB |
Output is correct |
11 |
Correct |
50 ms |
3664 KB |
Output is correct |
12 |
Correct |
40 ms |
3920 KB |
Output is correct |
13 |
Correct |
37 ms |
3408 KB |
Output is correct |
14 |
Correct |
100 ms |
3664 KB |
Output is correct |
15 |
Correct |
50 ms |
5452 KB |
Output is correct |
16 |
Correct |
40 ms |
3820 KB |
Output is correct |
17 |
Correct |
99 ms |
3920 KB |
Output is correct |
18 |
Correct |
47 ms |
5456 KB |
Output is correct |
19 |
Correct |
49 ms |
5272 KB |
Output is correct |
20 |
Correct |
97 ms |
3920 KB |
Output is correct |
21 |
Correct |
79 ms |
5712 KB |
Output is correct |
22 |
Correct |
69 ms |
4424 KB |
Output is correct |
23 |
Correct |
81 ms |
5564 KB |
Output is correct |
24 |
Correct |
65 ms |
4680 KB |
Output is correct |
25 |
Correct |
65 ms |
4688 KB |
Output is correct |
26 |
Correct |
65 ms |
5712 KB |
Output is correct |
27 |
Correct |
73 ms |
5484 KB |
Output is correct |
28 |
Correct |
76 ms |
5568 KB |
Output is correct |
29 |
Correct |
71 ms |
5712 KB |
Output is correct |
30 |
Correct |
70 ms |
4424 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
2 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
2 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
1 ms |
476 KB |
Output is correct |
58 |
Correct |
1 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
97 ms |
5704 KB |
Output is correct |
62 |
Correct |
93 ms |
5736 KB |
Output is correct |
63 |
Correct |
79 ms |
5712 KB |
Output is correct |
64 |
Correct |
96 ms |
5712 KB |
Output is correct |
65 |
Correct |
97 ms |
5712 KB |
Output is correct |
66 |
Correct |
116 ms |
5712 KB |
Output is correct |
67 |
Correct |
100 ms |
5540 KB |
Output is correct |
68 |
Correct |
70 ms |
5712 KB |
Output is correct |
69 |
Correct |
70 ms |
5712 KB |
Output is correct |
70 |
Correct |
65 ms |
5540 KB |
Output is correct |