127702024-12-30 11:01:40feheristvanSípálya (55 pont)cpp17Wrong answer 15/55500ms1512 KiB
#include <iostream>
#include <vector>

using namespace std;

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

int main()
{
    vector <int> v;
    int n, k;
    cin >> n >> k;
    int x;
    for(int i = 0; i < k ; i ++){
        cin >> x;
        v.push_back(x);
    }
    int 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
base15/55
1Accepted0/01ms512 KiB
2Accepted0/01ms320 KiB
3Accepted2/22ms320 KiB
4Accepted2/22ms320 KiB
5Accepted2/21ms320 KiB
6Accepted2/22ms404 KiB
7Wrong answer0/32ms404 KiB
8Wrong answer0/114ms404 KiB
9Wrong answer0/117ms320 KiB
10Wrong answer0/118ms408 KiB
11Accepted1/128ms320 KiB
12Accepted1/127ms416 KiB
13Accepted1/159ms320 KiB
14Accepted2/268ms380 KiB
15Accepted2/228ms416 KiB
16Time limit exceeded0/2499ms320 KiB
17Time limit exceeded0/2500ms1136 KiB
18Time limit exceeded0/2490ms1288 KiB
19Time limit exceeded0/3500ms1512 KiB
20Time limit exceeded0/2483ms568 KiB
21Time limit exceeded0/2500ms568 KiB
22Time limit exceeded0/2500ms516 KiB
23Time limit exceeded0/2499ms320 KiB
24Time limit exceeded0/2481ms320 KiB
25Time limit exceeded0/2500ms568 KiB
26Time limit exceeded0/2500ms756 KiB
27Time limit exceeded0/2483ms636 KiB
28Time limit exceeded0/3481ms568 KiB
29Time limit exceeded0/3500ms780 KiB
30Time limit exceeded0/3499ms796 KiB