# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240565 | 2020-06-20T05:00:04 Z | arnold518 | Feast (NOI19_feast) | C++14 | 175 ms | 15224 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 3e5; const ll INF = 1e13; int N, K; ll A[MAXN+10]; pll dp1[MAXN+10], dp2[MAXN+10]; ll ans; int solve(ll lambda) { int i, j; dp1[0]={-INF, 0}; dp2[0]={0, 0}; for(i=1; i<=N; i++) { if(dp1[i-1].first>dp2[i-1].first-lambda) dp1[i]={dp1[i-1].first+A[i]*2, dp1[i-1].second}; else dp1[i]={dp2[i-1].first-lambda+A[i]*2, dp2[i-1].second+1}; dp2[i]=max(dp1[i-1], dp2[i-1]); } ans=max(dp1[N].first, dp2[N].first); if(dp1[N].first>dp2[N].first) return dp1[N].second; else return dp2[N].second; } int main() { int i, j; scanf("%d%d", &N, &K); for(i=1; i<=N; i++) scanf("%lld", &A[i]); ll lo=0, hi=INF; while(lo+1<hi) { ll mid=lo+hi>>1; if(solve(mid*2+1)>=K) lo=mid; else hi=mid; } solve(lo*2); printf("%lld\n", ans/2+lo*K); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 112 ms | 14584 KB | Output is correct |
2 | Correct | 116 ms | 14712 KB | Output is correct |
3 | Correct | 123 ms | 14856 KB | Output is correct |
4 | Correct | 115 ms | 14840 KB | Output is correct |
5 | Correct | 116 ms | 14712 KB | Output is correct |
6 | Correct | 116 ms | 14456 KB | Output is correct |
7 | Correct | 114 ms | 14456 KB | Output is correct |
8 | Correct | 115 ms | 14840 KB | Output is correct |
9 | Correct | 124 ms | 14588 KB | Output is correct |
10 | Correct | 126 ms | 14796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 95 ms | 12920 KB | Output is correct |
2 | Correct | 105 ms | 13304 KB | Output is correct |
3 | Correct | 97 ms | 13048 KB | Output is correct |
4 | Correct | 99 ms | 13048 KB | Output is correct |
5 | Correct | 121 ms | 14456 KB | Output is correct |
6 | Correct | 101 ms | 12912 KB | Output is correct |
7 | Correct | 104 ms | 13176 KB | Output is correct |
8 | Correct | 126 ms | 14840 KB | Output is correct |
9 | Correct | 122 ms | 14456 KB | Output is correct |
10 | Correct | 109 ms | 13048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 140 ms | 15096 KB | Output is correct |
2 | Correct | 141 ms | 14712 KB | Output is correct |
3 | Correct | 136 ms | 14968 KB | Output is correct |
4 | Correct | 127 ms | 14712 KB | Output is correct |
5 | Correct | 134 ms | 14992 KB | Output is correct |
6 | Correct | 138 ms | 15048 KB | Output is correct |
7 | Correct | 131 ms | 15096 KB | Output is correct |
8 | Correct | 128 ms | 14840 KB | Output is correct |
9 | Correct | 135 ms | 15096 KB | Output is correct |
10 | Correct | 131 ms | 15096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 6 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 372 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 6 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 372 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 6 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 6 ms | 512 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 6 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 112 ms | 14584 KB | Output is correct |
2 | Correct | 116 ms | 14712 KB | Output is correct |
3 | Correct | 123 ms | 14856 KB | Output is correct |
4 | Correct | 115 ms | 14840 KB | Output is correct |
5 | Correct | 116 ms | 14712 KB | Output is correct |
6 | Correct | 116 ms | 14456 KB | Output is correct |
7 | Correct | 114 ms | 14456 KB | Output is correct |
8 | Correct | 115 ms | 14840 KB | Output is correct |
9 | Correct | 124 ms | 14588 KB | Output is correct |
10 | Correct | 126 ms | 14796 KB | Output is correct |
11 | Correct | 95 ms | 12920 KB | Output is correct |
12 | Correct | 105 ms | 13304 KB | Output is correct |
13 | Correct | 97 ms | 13048 KB | Output is correct |
14 | Correct | 99 ms | 13048 KB | Output is correct |
15 | Correct | 121 ms | 14456 KB | Output is correct |
16 | Correct | 101 ms | 12912 KB | Output is correct |
17 | Correct | 104 ms | 13176 KB | Output is correct |
18 | Correct | 126 ms | 14840 KB | Output is correct |
19 | Correct | 122 ms | 14456 KB | Output is correct |
20 | Correct | 109 ms | 13048 KB | Output is correct |
21 | Correct | 140 ms | 15096 KB | Output is correct |
22 | Correct | 141 ms | 14712 KB | Output is correct |
23 | Correct | 136 ms | 14968 KB | Output is correct |
24 | Correct | 127 ms | 14712 KB | Output is correct |
25 | Correct | 134 ms | 14992 KB | Output is correct |
26 | Correct | 138 ms | 15048 KB | Output is correct |
27 | Correct | 131 ms | 15096 KB | Output is correct |
28 | Correct | 128 ms | 14840 KB | Output is correct |
29 | Correct | 135 ms | 15096 KB | Output is correct |
30 | Correct | 131 ms | 15096 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 4 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 5 ms | 384 KB | Output is correct |
37 | Correct | 5 ms | 384 KB | Output is correct |
38 | Correct | 5 ms | 384 KB | Output is correct |
39 | Correct | 5 ms | 384 KB | Output is correct |
40 | Correct | 4 ms | 384 KB | Output is correct |
41 | Correct | 5 ms | 384 KB | Output is correct |
42 | Correct | 5 ms | 384 KB | Output is correct |
43 | Correct | 5 ms | 384 KB | Output is correct |
44 | Correct | 6 ms | 384 KB | Output is correct |
45 | Correct | 5 ms | 384 KB | Output is correct |
46 | Correct | 5 ms | 384 KB | Output is correct |
47 | Correct | 5 ms | 372 KB | Output is correct |
48 | Correct | 5 ms | 384 KB | Output is correct |
49 | Correct | 5 ms | 384 KB | Output is correct |
50 | Correct | 5 ms | 384 KB | Output is correct |
51 | Correct | 6 ms | 384 KB | Output is correct |
52 | Correct | 5 ms | 384 KB | Output is correct |
53 | Correct | 5 ms | 384 KB | Output is correct |
54 | Correct | 6 ms | 512 KB | Output is correct |
55 | Correct | 5 ms | 384 KB | Output is correct |
56 | Correct | 5 ms | 384 KB | Output is correct |
57 | Correct | 6 ms | 384 KB | Output is correct |
58 | Correct | 5 ms | 384 KB | Output is correct |
59 | Correct | 5 ms | 384 KB | Output is correct |
60 | Correct | 5 ms | 384 KB | Output is correct |
61 | Correct | 168 ms | 14840 KB | Output is correct |
62 | Correct | 158 ms | 15224 KB | Output is correct |
63 | Correct | 143 ms | 14688 KB | Output is correct |
64 | Correct | 171 ms | 15224 KB | Output is correct |
65 | Correct | 175 ms | 14968 KB | Output is correct |
66 | Correct | 171 ms | 14968 KB | Output is correct |
67 | Correct | 169 ms | 14712 KB | Output is correct |
68 | Correct | 132 ms | 15148 KB | Output is correct |
69 | Correct | 131 ms | 14712 KB | Output is correct |
70 | Correct | 129 ms | 14712 KB | Output is correct |