28042023-01-26 08:47:16gkataFasor (40)cpp17Runtime error 38/4075ms7956 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((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;
        }
    }
    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/03ms1876 KiB
2Accepted0/04ms2544 KiB
3Accepted2/22ms2252 KiB
4Accepted2/22ms2380 KiB
5Accepted2/22ms2584 KiB
6Accepted2/22ms2648 KiB
7Accepted2/22ms2792 KiB
8Accepted2/23ms3012 KiB
9Accepted2/24ms3612 KiB
10Accepted2/26ms3812 KiB
11Accepted2/26ms4040 KiB
12Accepted2/24ms3900 KiB
13Accepted2/239ms5632 KiB
14Runtime error0/237ms5636 KiB
15Accepted2/259ms7800 KiB
16Accepted2/268ms7804 KiB
17Accepted2/275ms7800 KiB
18Accepted2/275ms7804 KiB
19Accepted2/275ms7824 KiB
20Accepted2/223ms5844 KiB
21Accepted2/261ms7916 KiB
22Accepted2/275ms7956 KiB