219112026-01-14 10:18:54hunzombiSípálya (55 pont)cpp17Wrong answer 3/5568ms10500 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll n, k;
    cin >> n >> k;

    vector<ll> vec(n);
    unordered_map<ll, ll> last;
    last.reserve(n);

    for (ll i=0; i < n; i++) cin >> vec[i];

    multiset<ll> ms;
    ll curr = 0;
    ll ans = LLONG_MAX;

    for (int i = 0; i < n; i++) {
        ms.insert(vec[i] + i);
        curr += vec[i];

        if (i >= k) {
            ms.erase(ms.find(vec[i - k] + (i - k)));
            curr -= vec[i - k];
        }

        if (i >= k - 1) {
            ll L = i - k + 1;
            ll H = *ms.begin() - L;

            ll reqHeight = k * H - k * (k - 1) / 2;
            ll cost = curr - reqHeight;
            if (cost >= 0)
                ans = min(ans, cost);
        }
    }

    cout << ans << '\n';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base3/55
1Wrong answer0/01ms316 KiB
2Wrong answer0/01ms500 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/22ms316 KiB
6Wrong answer0/21ms444 KiB
7Wrong answer0/32ms316 KiB
8Wrong answer0/14ms608 KiB
9Wrong answer0/14ms564 KiB
10Wrong answer0/14ms564 KiB
11Wrong answer0/14ms772 KiB
12Accepted1/14ms564 KiB
13Wrong answer0/14ms564 KiB
14Wrong answer0/24ms784 KiB
15Wrong answer0/24ms564 KiB
16Accepted2/263ms3852 KiB
17Wrong answer0/267ms8284 KiB
18Wrong answer0/268ms8712 KiB
19Wrong answer0/364ms10500 KiB
20Wrong answer0/265ms4352 KiB
21Wrong answer0/261ms4100 KiB
22Wrong answer0/263ms4100 KiB
23Wrong answer0/264ms3844 KiB
24Wrong answer0/264ms4104 KiB
25Wrong answer0/267ms4356 KiB
26Wrong answer0/265ms4660 KiB
27Wrong answer0/264ms4932 KiB
28Wrong answer0/364ms4868 KiB
29Wrong answer0/364ms5128 KiB
30Wrong answer0/368ms5576 KiB