219522026-01-14 11:08:37sklausSípálya (55 pont)cpp17Wrong answer 15/5575ms1268 KiB
#include <iostream>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k; int t[n]; for(int i=0; i<n; i++)cin>>t[i];
    long long maxi=t[0],p,s=0;
    for(int i=0; i<k; i++){
        s+=(t[i]+i);
        if(t[i]+i>=maxi){p=i; maxi=t[i]+i;}}
    long long ar=k*maxi-s;
    for(int i=1; i<n-k+1; i++){
        maxi--;
        if(i==p+1){
            maxi=t[i];
            for(int j=0; j<k; j++){
                if(t[i+j]+j>=maxi){p=i+j; maxi=t[i+j]+j;}}}
        else if(t[i+k-1]-1>=maxi){maxi=t[i+k-1]-1; p=i+k-1;}
        s=s-t[i-1]+t[i+k-1];
        if(k*maxi-s<ar)ar=k*maxi-s;}
    cout<<ar;
    return 0;
}


SubtaskSumTestVerdictTimeMemory
base15/55
1Accepted0/01ms508 KiB
2Accepted0/01ms316 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted3/31ms316 KiB
8Wrong answer0/14ms316 KiB
9Wrong answer0/14ms316 KiB
10Wrong answer0/14ms408 KiB
11Accepted1/14ms508 KiB
12Wrong answer0/14ms316 KiB
13Accepted1/14ms316 KiB
14Accepted2/24ms508 KiB
15Wrong answer0/24ms316 KiB
16Accepted2/270ms1000 KiB
17Wrong answer0/268ms976 KiB
18Wrong answer0/268ms1080 KiB
19Wrong answer0/370ms1020 KiB
20Wrong answer0/271ms1060 KiB
21Wrong answer0/270ms1064 KiB
22Wrong answer0/271ms1044 KiB
23Wrong answer0/271ms1088 KiB
24Accepted2/275ms1020 KiB
25Wrong answer0/271ms1076 KiB
26Wrong answer0/271ms1056 KiB
27Wrong answer0/270ms976 KiB
28Wrong answer0/370ms1080 KiB
29Wrong answer0/374ms1136 KiB
30Wrong answer0/371ms1268 KiB