76872024-01-10 13:13:00gyjazminSípálya (55 pont)cpp17Wrong answer 15/55500ms7760 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/03ms1824 KiB
2Accepted0/03ms2016 KiB
3Accepted2/23ms2264 KiB
4Accepted2/23ms2588 KiB
5Accepted2/23ms2792 KiB
6Accepted2/23ms2892 KiB
7Wrong answer0/33ms2976 KiB
8Wrong answer0/116ms3304 KiB
9Wrong answer0/118ms3316 KiB
10Wrong answer0/120ms3532 KiB
11Accepted1/130ms3888 KiB
12Accepted1/132ms3976 KiB
13Accepted1/168ms4248 KiB
14Accepted2/278ms4260 KiB
15Accepted2/229ms4168 KiB
16Time limit exceeded0/2500ms4936 KiB
17Time limit exceeded0/2458ms6588 KiB
18Time limit exceeded0/2470ms6872 KiB
19Time limit exceeded0/3449ms7760 KiB
20Time limit exceeded0/2435ms5508 KiB
21Time limit exceeded0/2462ms5528 KiB
22Time limit exceeded0/2458ms5652 KiB
23Time limit exceeded0/2462ms5420 KiB
24Time limit exceeded0/2458ms5640 KiB
25Time limit exceeded0/2462ms5796 KiB
26Time limit exceeded0/2458ms5740 KiB
27Time limit exceeded0/2467ms5952 KiB
28Time limit exceeded0/3462ms5964 KiB
29Time limit exceeded0/3465ms6248 KiB
30Time limit exceeded0/3469ms6404 KiB