Submission #952678

# Submission time Handle Problem Language Result Execution time Memory
952678 2024-03-24T13:37:30 Z Beerus13 Holding (COCI20_holding) C++14
110 / 110
90 ms 14068 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
const int N = 1e2 + 5;

bool maximize(auto &a, auto b) {
    if(a >= b) return true;
    a = b;
    return false;
}

int n, a[N], k, l, r;
int pre[N][N * N], suf[N][N * N], tmp[N][N * N];

void solve() {
    cin >> n >> l >> r >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int j = 1; j < l; ++j) {
        swap(tmp, pre);
        memset(pre, 0, sizeof(pre));
        for(int i = l; i <= r; ++i) {
            for(int cost = 0; cost <= k; ++cost) {
                maximize(pre[i][cost], pre[i - 1][cost]);
                maximize(pre[i][cost], tmp[i][cost]);
                if(cost + i - j <= k) 
                    maximize(pre[i][cost + i - j], tmp[i - 1][cost] + a[i] - a[j]);
            }
        }
    }
    for(int j = n; j > r; --j) {
        swap(tmp, suf);
        memset(suf, 0, sizeof(suf));
        for(int i = r; i >= l; --i) {
            for(int cost = 0; cost <= k; ++cost) {
                maximize(suf[i][cost], suf[i + 1][cost]);
                maximize(suf[i][cost], tmp[i][cost]);
                if(cost - i + j <= k) 
                    maximize(suf[i][cost - i + j], tmp[i + 1][cost] + a[i] - a[j]);
            }
        }
    }
    int ans = 0, res = 0;
    res = max(pre[r][k], suf[l][k]);
    for(int i = l; i <= r; ++i) {
        for(int cost = 0; cost <= k; ++cost) {
            maximize(res, pre[i][cost] + suf[i + 1][k - cost]);
        }
    }
    for(int i = l; i <= r; ++i) ans += a[i];
    cout << ans - res << '\n';
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}

Compilation message

holding.cpp:7:15: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
    7 | bool maximize(auto &a, auto b) {
      |               ^~~~
holding.cpp:7:24: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
    7 | bool maximize(auto &a, auto b) {
      |                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9304 KB Output is correct
2 Correct 9 ms 9308 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 9308 KB Output is correct
5 Correct 6 ms 9476 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 9 ms 9316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9304 KB Output is correct
2 Correct 9 ms 9308 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 9308 KB Output is correct
5 Correct 6 ms 9476 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 9 ms 9316 KB Output is correct
8 Correct 36 ms 9308 KB Output is correct
9 Correct 36 ms 9552 KB Output is correct
10 Correct 26 ms 9308 KB Output is correct
11 Correct 22 ms 9308 KB Output is correct
12 Correct 12 ms 9304 KB Output is correct
13 Correct 33 ms 9424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9304 KB Output is correct
2 Correct 9 ms 9308 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 9308 KB Output is correct
5 Correct 6 ms 9476 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 9 ms 9316 KB Output is correct
8 Correct 36 ms 9308 KB Output is correct
9 Correct 36 ms 9552 KB Output is correct
10 Correct 26 ms 9308 KB Output is correct
11 Correct 22 ms 9308 KB Output is correct
12 Correct 12 ms 9304 KB Output is correct
13 Correct 33 ms 9424 KB Output is correct
14 Correct 59 ms 13872 KB Output is correct
15 Correct 44 ms 13904 KB Output is correct
16 Correct 50 ms 14068 KB Output is correct
17 Correct 42 ms 13868 KB Output is correct
18 Correct 37 ms 13916 KB Output is correct
19 Correct 33 ms 9528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9304 KB Output is correct
2 Correct 9 ms 9308 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 9308 KB Output is correct
5 Correct 6 ms 9476 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 9 ms 9316 KB Output is correct
8 Correct 36 ms 9308 KB Output is correct
9 Correct 36 ms 9552 KB Output is correct
10 Correct 26 ms 9308 KB Output is correct
11 Correct 22 ms 9308 KB Output is correct
12 Correct 12 ms 9304 KB Output is correct
13 Correct 33 ms 9424 KB Output is correct
14 Correct 59 ms 13872 KB Output is correct
15 Correct 44 ms 13904 KB Output is correct
16 Correct 50 ms 14068 KB Output is correct
17 Correct 42 ms 13868 KB Output is correct
18 Correct 37 ms 13916 KB Output is correct
19 Correct 33 ms 9528 KB Output is correct
20 Correct 82 ms 13904 KB Output is correct
21 Correct 88 ms 14032 KB Output is correct
22 Correct 81 ms 13916 KB Output is correct
23 Correct 90 ms 13856 KB Output is correct
24 Correct 36 ms 13904 KB Output is correct
25 Correct 81 ms 9308 KB Output is correct