127732024-12-30 11:10:19feheristvanSípálya (55 pont)cpp17Wrong answer 18/55500ms2744 KiB
#include <iostream>
#include <vector>

using namespace std;

long long ossz(int k, vector <long long> v){
    int max_poz;
    long long maxx = 0;
    for(int i = 0; i < k; i ++){
        if(v[i] >= maxx){
            maxx = v[i];
            max_poz = i;
        }
    }
    if(maxx < k - max_poz){
        maxx = k - max_poz;
        v[max_poz] = maxx;
    }
    long long osszeg = 0;
    for(int i = 0; i < k; i ++){
        osszeg = osszeg + maxx + (max_poz - i) - v[i];
    }
    return osszeg;
}

int main()
{
    vector <long long> v;
    int n, k;
    cin >> n >> k;
    long long x;
    for(int i = 0; i < k ; i ++){
        cin >> x;
        v.push_back(x);
    }
    long long min_osszeg = ossz(k, v), akt_osszeg;
    for(int i = k; i < n; i ++){
        cin >> x;
        v.erase(v.begin());
        v.push_back(x);
        akt_osszeg = ossz(k, v);
        if(akt_osszeg < min_osszeg)
            min_osszeg = akt_osszeg;
    }
    cout << min_osszeg;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/01ms320 KiB
2Accepted0/01ms320 KiB
3Accepted2/22ms320 KiB
4Accepted2/22ms320 KiB
5Accepted2/22ms320 KiB
6Accepted2/22ms320 KiB
7Accepted3/32ms508 KiB
8Wrong answer0/114ms412 KiB
9Wrong answer0/117ms412 KiB
10Wrong answer0/119ms416 KiB
11Accepted1/128ms320 KiB
12Accepted1/128ms432 KiB
13Accepted1/165ms320 KiB
14Accepted2/276ms320 KiB
15Accepted2/228ms320 KiB
16Time limit exceeded0/2500ms568 KiB
17Time limit exceeded0/2500ms1960 KiB
18Time limit exceeded0/2500ms2024 KiB
19Time limit exceeded0/3476ms2744 KiB
20Time limit exceeded0/2488ms692 KiB
21Time limit exceeded0/2500ms784 KiB
22Time limit exceeded0/2479ms568 KiB
23Time limit exceeded0/2500ms568 KiB
24Time limit exceeded0/2486ms568 KiB
25Time limit exceeded0/2500ms772 KiB
26Time limit exceeded0/2485ms756 KiB
27Time limit exceeded0/2500ms948 KiB
28Time limit exceeded0/3476ms948 KiB
29Time limit exceeded0/3500ms948 KiB
30Time limit exceeded0/3500ms948 KiB