82002024-01-12 18:18:41gergomiszoriSípálya (55 pont)cpp17Wrong answer 0/55479ms5132 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl "\n"
#define pll pair<ll,ll>
#define fs first
#define sc second

const ll MOD = 1e9+7;

void solve()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    
    for(ll i = 0; i < n; i++) cin >> a[i];
    
    if(k == 1)
    {
        cout << 0 << endl;
        return;
    }

    ll ans = LLONG_MAX-1;

    for(ll i = 0; i < n-k+1; i++)
    {
        ll maxe = a[i];
        ll maxl = 0;
        /*
        for(ll j = 0; j < k; j++)
        {
            if(a[i+j] >= maxe)
            {
                maxe = a[i+j];
                maxl = j;
            }
        }
        */

        ll ans2 = 0;
        
        for(ll j = 0; j < k; j++)
        {
            ll magas = maxl-j + maxe;
            ans2 += magas - a[i+j];
        }
        ans = min(ans, ans2);
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms2104 KiB
2Wrong answer0/03ms2140 KiB
3Wrong answer0/23ms2304 KiB
4Wrong answer0/23ms2500 KiB
5Wrong answer0/23ms2680 KiB
6Wrong answer0/23ms2756 KiB
7Wrong answer0/33ms2760 KiB
8Wrong answer0/17ms3080 KiB
9Wrong answer0/18ms3296 KiB
10Wrong answer0/18ms3228 KiB
11Wrong answer0/112ms3376 KiB
12Wrong answer0/112ms3360 KiB
13Wrong answer0/124ms3384 KiB
14Wrong answer0/227ms3360 KiB
15Wrong answer0/212ms3384 KiB
16Time limit exceeded0/2479ms4364 KiB
17Time limit exceeded0/2453ms4332 KiB
18Time limit exceeded0/2444ms4456 KiB
19Time limit exceeded0/3465ms4352 KiB
20Time limit exceeded0/2430ms4540 KiB
21Time limit exceeded0/2442ms4608 KiB
22Time limit exceeded0/2462ms4692 KiB
23Time limit exceeded0/2449ms4656 KiB
24Time limit exceeded0/2428ms4928 KiB
25Time limit exceeded0/2469ms5132 KiB
26Time limit exceeded0/2474ms5068 KiB
27Time limit exceeded0/2458ms4888 KiB
28Time limit exceeded0/3465ms4888 KiB
29Time limit exceeded0/3453ms4800 KiB
30Time limit exceeded0/3474ms4868 KiB