28032023-01-26 08:42:23gkataFasor (40)cpp17Runtime error 38/4075ms8300 KiB
#include <iostream>
//#include <fstream>
#include <vector>
#include <climits>
#define ll long long

using namespace std;

//ifstream cin("fasor.in");
//ofstream cout("fasor.out");

vector <ll>x;

ll n,k,i,j,a,maxi=LONG_MIN,maxi2=LONG_MIN,pos,pos2;

int main()
{
    cin>>n>>k;
    for(i=1;i<=n;++i)
    {
        cin>>a;
        x.push_back(a);
    }

    for(i=0;i<=k;++i)
        if(x[i]>maxi)
        {
            maxi=x[i];
            pos=i;
        }
    for(i=(pos+1);i<=(pos+k);++i)
        if(x[i]>maxi2)
        {
            maxi2=x[i];
            pos2=i;
        }
    if(maxi>=maxi2) cout<<pos+1;
        else
        {
            while(maxi<maxi2)
            {
                pos=pos2;
                maxi=maxi2;
                if((pos+k)<x.size())
                {
                    for(i=(pos+1);i<=(pos+k);++i)
                    if(x[i]>maxi2)
                    {
                        maxi2=x[i];
                        pos2=i;
                    }
                }
                else
                {
                    for(i=(pos+1);i<x.size();++i)
                    if(x[i]>maxi2)
                    {
                        maxi2=x[i];
                        pos2=i;
                    }
                }

            }
            cout<<pos+1;
        }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/03ms1872 KiB
2Accepted0/04ms2492 KiB
3Accepted2/22ms2272 KiB
4Accepted2/22ms2476 KiB
5Accepted2/22ms2676 KiB
6Accepted2/22ms2784 KiB
7Accepted2/22ms2996 KiB
8Accepted2/23ms3212 KiB
9Accepted2/24ms3556 KiB
10Accepted2/26ms3560 KiB
11Accepted2/26ms3816 KiB
12Accepted2/24ms4088 KiB
13Accepted2/237ms5844 KiB
14Runtime error0/235ms5900 KiB
15Accepted2/261ms8036 KiB
16Accepted2/268ms8040 KiB
17Accepted2/275ms7968 KiB
18Accepted2/275ms8300 KiB
19Accepted2/274ms7984 KiB
20Accepted2/223ms5912 KiB
21Accepted2/261ms7984 KiB
22Accepted2/274ms7988 KiB