29292023-02-04 15:54:55horvathabelFasor (40)cpp17Runtime error 34/40270ms9916 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k;
	cin>>n>>k;

	vector<int> mxk;
	mxk.push_back(-1);
	int mx=0;  
	vector<int> m;
	for (int i=0; i<k;i++){
		int z;
		cin>>z;
		m.push_back(z);
		mx=max(mx,z);
		mxk.push_back(mx);
	}
	for (int i=k;i<n;i++){
		int z; 
		cin>>z;
		m.push_back(z);
		mx=max(mx, z);
		if (m[i-k]==mx){
			mx=0; 
			for (int j=i-k+1;j<=i;j++){
				mx=max(mx, m[j]);
			}
		}
		
		mxk.push_back(mx);
	}
	mx=0; 
	for (int i=n-k+1;i<n;i++){
		mx=max(mx, m[i]);
		mxk.push_back(mx);
	}
	mxk.push_back(-1);
	for (int i=0; i<n;i++){
		if (m[i]>=mxk[i] && m[i]>=mxk[i+k+1]){
			 cout<<i+1;
			 return 0;  
		}
	}
	cout<<-1;
}
SubtaskSumTestVerdictTimeMemory
base34/40
1Accepted0/03ms1832 KiB
2Accepted0/06ms2384 KiB
3Accepted2/23ms2312 KiB
4Accepted2/22ms2276 KiB
5Accepted2/23ms2408 KiB
6Accepted2/23ms2396 KiB
7Accepted2/23ms2420 KiB
8Accepted2/23ms2552 KiB
9Accepted2/26ms3140 KiB
10Accepted2/26ms3348 KiB
11Accepted2/27ms3684 KiB
12Accepted2/24ms3888 KiB
13Accepted2/239ms5388 KiB
14Runtime error0/237ms7184 KiB
15Time limit exceeded0/2263ms4660 KiB
16Accepted2/2103ms7564 KiB
17Accepted2/283ms9720 KiB
18Accepted2/275ms7512 KiB
19Time limit exceeded0/2270ms4892 KiB
20Accepted2/225ms7028 KiB
21Accepted2/264ms9916 KiB
22Accepted2/275ms7820 KiB