76962024-01-10 13:36:46gyjazminSípálya (55 pont)cpp17Wrong answer 15/55479ms7384 KiB

#include <iostream>
#include<vector>
using namespace std;
vector<int> hozzaadott;
vector<int> h;
int n, k;
typedef long long ll;
int kisz(int a) {
    int mx = 0;
    int mxh = 0;
    for (int i = a;i < a + k;i++) {
        if (h[i] > mx) {
            mx = h[i];
            mxh = i-a;
        }
    }
    vector<int> opt(k);
    vector<int> kiegyh(k);
    opt[0] = mx + mxh;
    kiegyh[0] = opt[0];
    for (int i = 1;i < k;i++) {
        opt[i] = opt[i - 1] - 1;
        kiegyh[i] = kiegyh[i - 1] + opt[i];
    }
    return (kiegyh[k - 1] - (hozzaadott[k-1+a]-hozzaadott[a-1]));
}
int main()
{
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    h.resize(n);
    hozzaadott.resize(n);
    cin >> h[0];
    hozzaadott[0] = h[0];
    for (int i = 1;i < n;i++) {
        cin >> h[i];
        hozzaadott[i] = hozzaadott[i - 1] + h[i];
    }
    int mx = 0;
    int mxh = 0;
    for (int i = 0;i < 0 + k;i++) {
        if (h[i] > mx) {
            mx = h[i];
            mxh = i - 0;
        }
    }
    vector<int> opt(k);
    vector<int> kiegyh(k);
    opt[0] = mx + mxh;
    kiegyh[0] = opt[0];
    for (int i = 1;i < k;i++) {
        opt[i] = opt[i - 1] - 1;
        kiegyh[i] = kiegyh[i - 1] + opt[i];
    }
    int legk = kiegyh[k-1]-hozzaadott[k-1];
    for (int i = 1;i < n - k;i++) {
        legk = min(legk, kisz(i));
    }
    cout << legk << endl;
}

























    /*vector<int> opt(n);
    vector<int> kiegyh(n);
    opt[0] = mx + mxh;
    kiegyh[0] = opt[0];
    for (int i = 1;i < n;i++) {
        opt[i] = opt[i - 1] - 1;
        kiegyh[i] = kiegyh[i - 1] + opt[i];
    }*/
    /*int legk = INT_MAX;// =kiegyh[k-1]-hozzaadott[k-1];s
    for (int i = 0;i < n-k;i++) {
        legk = min(legk, kisz(i));//(kiegyh[i + k-1] - kiegyh[i - 1])-(hozzaadott[i+k-1]-hozzaadott[i-1]));
    }*/
    //int vmi =kisz(0);
    //cout << legk << endl;

SubtaskSumTestVerdictTimeMemory
base15/55
1Accepted0/03ms1828 KiB
2Accepted0/03ms2180 KiB
3Accepted2/23ms2284 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2676 KiB
6Accepted2/23ms2764 KiB
7Wrong answer0/33ms2892 KiB
8Wrong answer0/116ms3176 KiB
9Wrong answer0/119ms3300 KiB
10Wrong answer0/121ms3580 KiB
11Accepted1/130ms3720 KiB
12Accepted1/129ms3668 KiB
13Accepted1/164ms3888 KiB
14Accepted2/279ms3984 KiB
15Accepted2/230ms4048 KiB
16Time limit exceeded0/2474ms4836 KiB
17Time limit exceeded0/2474ms6372 KiB
18Time limit exceeded0/2455ms6512 KiB
19Time limit exceeded0/3453ms7384 KiB
20Time limit exceeded0/2444ms5304 KiB
21Time limit exceeded0/2462ms5184 KiB
22Time limit exceeded0/2449ms5508 KiB
23Time limit exceeded0/2451ms5320 KiB
24Time limit exceeded0/2474ms5344 KiB
25Time limit exceeded0/2446ms5548 KiB
26Time limit exceeded0/2425ms5584 KiB
27Time limit exceeded0/2458ms5680 KiB
28Time limit exceeded0/3458ms5904 KiB
29Time limit exceeded0/3465ms6144 KiB
30Time limit exceeded0/3479ms6300 KiB