74962024-01-09 10:59:40AblablablaSípálya (55 pont)cpp14Wrong answer 11/5598ms12340 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int INF = 2e9 + 7;

int ind = 0;

struct comp{
    bool operator()(pii a, pii b){
        int c = a.first + a.second - ind;
        int d = b.first + b.second - ind;

        return c < d;
    }
};

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> hegyek(n, 0);

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

    vector<int> pref(n + 1, 0);
    for(int i = 1; i <= n; i++){
        pref[i] = pref[i - 1] + hegyek[i - 1];
    }

    vector<int> kezdo(n, 0);
    priority_queue<pii, vector<pii>, comp> sorrend;

    for(int i = 0; i < k; i++){
        sorrend.push({hegyek[i], i});
    }

    for(int i = 0; i + k - 1 < n; i++){
        ind = i;
        sorrend.push({hegyek[i + k - 1], i + k - 1});
        while(sorrend.top().second < i){
            sorrend.pop();
        }

        int kesobb = sorrend.top().second - i;
        kezdo[i] = sorrend.top().first + kesobb;
    }

    int mini = INF;
    for(int i = 0; i + k - 1 < n; i++){
        int koltseg = (kezdo[i] + kezdo[i] - k + 1) * k / 2 - (pref[i + k] - pref[i]);
        mini = min(mini, koltseg);
    }
    cout << mini << "\n";
}
SubtaskSumTestVerdictTimeMemory
base11/55
1Accepted0/03ms1812 KiB
2Accepted0/03ms2148 KiB
3Accepted2/23ms2312 KiB
4Wrong answer0/23ms2476 KiB
5Wrong answer0/23ms2436 KiB
6Wrong answer0/23ms2516 KiB
7Wrong answer0/33ms2592 KiB
8Accepted1/17ms2976 KiB
9Accepted1/17ms3236 KiB
10Accepted1/17ms3332 KiB
11Accepted1/17ms2984 KiB
12Accepted1/17ms3032 KiB
13Wrong answer0/17ms3300 KiB
14Accepted2/27ms3264 KiB
15Accepted2/27ms3236 KiB
16Wrong answer0/293ms9872 KiB
17Wrong answer0/286ms12112 KiB
18Wrong answer0/286ms12072 KiB
19Wrong answer0/386ms12076 KiB
20Wrong answer0/287ms12192 KiB
21Wrong answer0/290ms12340 KiB
22Wrong answer0/292ms12300 KiB
23Wrong answer0/290ms12200 KiB
24Wrong answer0/298ms12212 KiB
25Wrong answer0/287ms12216 KiB
26Wrong answer0/287ms12276 KiB
27Wrong answer0/286ms12296 KiB
28Wrong answer0/386ms12272 KiB
29Wrong answer0/386ms12232 KiB
30Wrong answer0/387ms12216 KiB