Submission #1100499

# Submission time Handle Problem Language Result Execution time Memory
1100499 2024-10-14T06:19:02 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
218 ms 14164 KB
/*For today, you happen to be the defeated. But what will you become tomorrow?*/
 
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
 
const int N = 300005;
const ll inf = (1ll << 60);
int arr[N], n, k;
array<ll, 2> dp[N][2];
 
array<ll, 2> f(ll c) {
    for(int i = 0; i <= n; i ++) {
        dp[i][0] = {0, 0};
        dp[i][1] = {-inf, 0};
    }
 
    for(int i = 1; i <= n; i ++) {
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = {dp[i - 1][1][0] + (ll)arr[i], dp[i - 1][1][1]};
        array<ll, 2> cur = {dp[i - 1][0][0] + (ll)arr[i] - c, dp[i - 1][0][1] - 1};
        dp[i][1] = max(dp[i][1], cur);
        dp[i][0] = max(dp[i][0], dp[i][1]);
        
    }
    return dp[n][0];
}
void solve() {
    
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) cin >> arr[i];    
    ll lo = 0, hi = (1ll << 60), ans = 0;
 
    while(lo <= hi) {
        ll mid = (lo + hi) / 2;
        array<ll, 2> yo = f(mid);

        if(-yo[1] <= k) {
            ans = yo[0] + k * mid;
            hi = mid - 1;
        }
        else {
            lo = mid + 1;
        }
    }
 
    cout << ans << '\n';
}
 
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
        
    int t = 1;
    // cin >> t;
    
    while(t--){
        solve();
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 184 ms 13660 KB Output is correct
2 Correct 183 ms 13644 KB Output is correct
3 Correct 187 ms 13932 KB Output is correct
4 Correct 184 ms 13772 KB Output is correct
5 Correct 185 ms 13652 KB Output is correct
6 Correct 184 ms 13668 KB Output is correct
7 Correct 192 ms 13648 KB Output is correct
8 Correct 189 ms 13660 KB Output is correct
9 Correct 197 ms 13652 KB Output is correct
10 Correct 188 ms 13776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 12116 KB Output is correct
2 Correct 138 ms 12112 KB Output is correct
3 Correct 139 ms 11856 KB Output is correct
4 Correct 146 ms 12112 KB Output is correct
5 Correct 186 ms 13784 KB Output is correct
6 Correct 129 ms 12104 KB Output is correct
7 Correct 145 ms 12120 KB Output is correct
8 Correct 197 ms 13644 KB Output is correct
9 Correct 188 ms 13780 KB Output is correct
10 Correct 143 ms 12120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 13896 KB Output is correct
2 Correct 142 ms 13912 KB Output is correct
3 Correct 133 ms 14164 KB Output is correct
4 Correct 140 ms 13916 KB Output is correct
5 Correct 124 ms 13908 KB Output is correct
6 Correct 129 ms 13916 KB Output is correct
7 Correct 141 ms 13904 KB Output is correct
8 Correct 138 ms 13884 KB Output is correct
9 Correct 142 ms 13924 KB Output is correct
10 Correct 140 ms 13840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 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 2384 KB Output is correct
18 Correct 2 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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 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 2384 KB Output is correct
18 Correct 2 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 2540 KB Output is correct
22 Correct 2 ms 2384 KB Output is correct
23 Correct 2 ms 2540 KB Output is correct
24 Correct 2 ms 2528 KB Output is correct
25 Correct 2 ms 2552 KB Output is correct
26 Correct 2 ms 2384 KB Output is correct
27 Correct 2 ms 2384 KB Output is correct
28 Correct 2 ms 2528 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 2 ms 2600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 13660 KB Output is correct
2 Correct 183 ms 13644 KB Output is correct
3 Correct 187 ms 13932 KB Output is correct
4 Correct 184 ms 13772 KB Output is correct
5 Correct 185 ms 13652 KB Output is correct
6 Correct 184 ms 13668 KB Output is correct
7 Correct 192 ms 13648 KB Output is correct
8 Correct 189 ms 13660 KB Output is correct
9 Correct 197 ms 13652 KB Output is correct
10 Correct 188 ms 13776 KB Output is correct
11 Correct 112 ms 12116 KB Output is correct
12 Correct 138 ms 12112 KB Output is correct
13 Correct 139 ms 11856 KB Output is correct
14 Correct 146 ms 12112 KB Output is correct
15 Correct 186 ms 13784 KB Output is correct
16 Correct 129 ms 12104 KB Output is correct
17 Correct 145 ms 12120 KB Output is correct
18 Correct 197 ms 13644 KB Output is correct
19 Correct 188 ms 13780 KB Output is correct
20 Correct 143 ms 12120 KB Output is correct
21 Correct 139 ms 13896 KB Output is correct
22 Correct 142 ms 13912 KB Output is correct
23 Correct 133 ms 14164 KB Output is correct
24 Correct 140 ms 13916 KB Output is correct
25 Correct 124 ms 13908 KB Output is correct
26 Correct 129 ms 13916 KB Output is correct
27 Correct 141 ms 13904 KB Output is correct
28 Correct 138 ms 13884 KB Output is correct
29 Correct 142 ms 13924 KB Output is correct
30 Correct 140 ms 13840 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 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 2384 KB Output is correct
48 Correct 2 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 2540 KB Output is correct
52 Correct 2 ms 2384 KB Output is correct
53 Correct 2 ms 2540 KB Output is correct
54 Correct 2 ms 2528 KB Output is correct
55 Correct 2 ms 2552 KB Output is correct
56 Correct 2 ms 2384 KB Output is correct
57 Correct 2 ms 2384 KB Output is correct
58 Correct 2 ms 2528 KB Output is correct
59 Correct 2 ms 2384 KB Output is correct
60 Correct 2 ms 2600 KB Output is correct
61 Correct 199 ms 13904 KB Output is correct
62 Correct 218 ms 13904 KB Output is correct
63 Correct 156 ms 13896 KB Output is correct
64 Correct 198 ms 14072 KB Output is correct
65 Correct 186 ms 13896 KB Output is correct
66 Correct 179 ms 14028 KB Output is correct
67 Correct 178 ms 13904 KB Output is correct
68 Correct 129 ms 13896 KB Output is correct
69 Correct 137 ms 13904 KB Output is correct
70 Correct 126 ms 13904 KB Output is correct