Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
967 B
3
Indexable
Never
#include <bits/stdc++.h>

#define ll long long int
#define ull unsigned long long int
using namespace std;

void solve()
{
    int n, k;
    cin >> n >> k;

    vector<int> bells(n);
    for (int i = 0; i < n; i++) {
        cin >> bells[i];
    }

    vector<int> boxs(k, 0);
    int cur = 0, flag = 0;

    for (int i = n - 1; i >= 0; i--) {
        boxs[cur] += bells[i];
        if (cur == k - 1 && flag == 0) {
            cur++;
            flag = 1;
        }
        else if (cur == 0) {
            flag = 0;
        }

        if (flag == 1) {
            cur--;
        }
        else {
            cur++;
        }
    }

    cout << *max_element(boxs.begin(), boxs.end()) << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    solve();

    return 0;
}
Leave a Comment