28062023-01-26 10:18:01gkataFasor (40)cpp17Runtime error 38/4076ms7644 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;
        }
    if(maxi==x[n-1]) cout<<pos+1;
    else
    {
        if((pos+k)<n)
    {
        for(i=(pos+1);i<=(pos+k);++i)
        if(x[i]>maxi2)
        {
            maxi2=x[i];
            pos2=i;
        }
    }
    else
    {
        for(i=(pos+1);i<n;++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)<n)
                {
                    for(i=(pos+1);i<=(pos+k);++i)
                    if(x[i]>maxi2)
                    {
                        maxi2=x[i];
                        pos2=i;
                    }
                }
                else
                {
                    for(i=(pos+1);i<n;++i)
                    if(x[i]>maxi2)
                    {
                        maxi2=x[i];
                        pos2=i;
                    }
                }

            }
            cout<<pos+1;
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/03ms1872 KiB
2Accepted0/04ms2544 KiB
3Accepted2/22ms2328 KiB
4Accepted2/22ms2400 KiB
5Accepted2/22ms2376 KiB
6Accepted2/22ms2720 KiB
7Accepted2/22ms2660 KiB
8Accepted2/23ms2692 KiB
9Accepted2/24ms3164 KiB
10Accepted2/26ms3180 KiB
11Accepted2/26ms3184 KiB
12Accepted2/24ms3184 KiB
13Accepted2/237ms5060 KiB
14Runtime error0/235ms5120 KiB
15Accepted2/259ms7188 KiB
16Accepted2/267ms7228 KiB
17Accepted2/276ms7160 KiB
18Accepted2/274ms7352 KiB
19Accepted2/274ms7364 KiB
20Accepted2/223ms5476 KiB
21Accepted2/261ms7556 KiB
22Accepted2/272ms7644 KiB