76852024-01-10 13:08:29gyjazminSípálya (55 pont)cpp17Wrong answer 15/55486ms6920 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()
{
    cin >> n >> k;
    h.resize(n);
    //int mx = 0;
    //int mxh = 0;
    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];
        /*if (h[i] > mx) {
            mx = h[i];
            mxh = 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/03ms1680 KiB
2Accepted0/03ms2080 KiB
3Accepted2/23ms2328 KiB
4Accepted2/23ms2368 KiB
5Accepted2/23ms2580 KiB
6Accepted2/24ms2664 KiB
7Wrong answer0/34ms2772 KiB
8Wrong answer0/118ms3060 KiB
9Wrong answer0/121ms3072 KiB
10Wrong answer0/125ms3072 KiB
11Accepted1/135ms3080 KiB
12Accepted1/132ms3080 KiB
13Accepted1/170ms3392 KiB
14Accepted2/279ms3468 KiB
15Accepted2/235ms3544 KiB
16Time limit exceeded0/2435ms4572 KiB
17Time limit exceeded0/2474ms5936 KiB
18Time limit exceeded0/2458ms6188 KiB
19Time limit exceeded0/3470ms6920 KiB
20Time limit exceeded0/2479ms4888 KiB
21Time limit exceeded0/2462ms4800 KiB
22Time limit exceeded0/2470ms5060 KiB
23Time limit exceeded0/2467ms4812 KiB
24Time limit exceeded0/2458ms5140 KiB
25Time limit exceeded0/2455ms5288 KiB
26Time limit exceeded0/2453ms5136 KiB
27Time limit exceeded0/2449ms5388 KiB
28Time limit exceeded0/3469ms5308 KiB
29Time limit exceeded0/3486ms5596 KiB
30Time limit exceeded0/3483ms5772 KiB