81992024-01-12 18:16:27gergomiszoriSípálya (55 pont)cpp17Wrong answer 18/55500ms5576 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 = -1;
        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
base18/55
1Accepted0/03ms1828 KiB
2Accepted0/03ms2056 KiB
3Accepted2/23ms2552 KiB
4Accepted2/23ms2424 KiB
5Accepted2/23ms2648 KiB
6Accepted2/23ms2756 KiB
7Accepted3/33ms2932 KiB
8Wrong answer0/114ms3356 KiB
9Wrong answer0/117ms3296 KiB
10Wrong answer0/119ms3348 KiB
11Accepted1/128ms3296 KiB
12Accepted1/127ms3548 KiB
13Accepted1/161ms3568 KiB
14Accepted2/268ms3840 KiB
15Accepted2/228ms3716 KiB
16Time limit exceeded0/2500ms4372 KiB
17Time limit exceeded0/2467ms4492 KiB
18Time limit exceeded0/2465ms4432 KiB
19Time limit exceeded0/3453ms4680 KiB
20Time limit exceeded0/2465ms4684 KiB
21Time limit exceeded0/2442ms4744 KiB
22Time limit exceeded0/2437ms5052 KiB
23Time limit exceeded0/2462ms4996 KiB
24Time limit exceeded0/2458ms4860 KiB
25Time limit exceeded0/2449ms5176 KiB
26Time limit exceeded0/2470ms5124 KiB
27Time limit exceeded0/2467ms5436 KiB
28Time limit exceeded0/3474ms5576 KiB
29Time limit exceeded0/3453ms5464 KiB
30Time limit exceeded0/3474ms5384 KiB