29302023-02-04 15:55:36horvathabelFasor (40)cpp17Runtime error 34/40275ms9884 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio();
	cin.tie(0);
	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/03ms1684 KiB
2Accepted0/04ms2248 KiB
3Accepted2/23ms2180 KiB
4Accepted2/22ms2140 KiB
5Accepted2/23ms2388 KiB
6Accepted2/23ms2520 KiB
7Accepted2/23ms2784 KiB
8Accepted2/23ms2980 KiB
9Accepted2/26ms3260 KiB
10Accepted2/26ms3592 KiB
11Accepted2/27ms3596 KiB
12Accepted2/24ms3916 KiB
13Accepted2/235ms5340 KiB
14Runtime error0/234ms7024 KiB
15Time limit exceeded0/2275ms4400 KiB
16Accepted2/294ms7200 KiB
17Accepted2/276ms9540 KiB
18Accepted2/268ms7412 KiB
19Time limit exceeded0/2261ms4992 KiB
20Accepted2/220ms7228 KiB
21Accepted2/257ms9884 KiB
22Accepted2/267ms7564 KiB