29382023-02-04 17:17:14horvathabelFasor (40)cpp17Runtime error 34/40286ms10072 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	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/03ms1828 KiB
2Accepted0/04ms2440 KiB
3Accepted2/23ms2364 KiB
4Accepted2/23ms2568 KiB
5Accepted2/23ms2660 KiB
6Accepted2/23ms2784 KiB
7Accepted2/23ms2804 KiB
8Accepted2/23ms2980 KiB
9Accepted2/24ms3380 KiB
10Accepted2/24ms3252 KiB
11Accepted2/24ms3516 KiB
12Accepted2/23ms3720 KiB
13Accepted2/214ms5532 KiB
14Runtime error0/216ms7076 KiB
15Time limit exceeded0/2247ms9616 KiB
16Accepted2/257ms7668 KiB
17Accepted2/235ms9704 KiB
18Accepted2/226ms7596 KiB
19Time limit exceeded0/2286ms5008 KiB
20Accepted2/212ms7140 KiB
21Accepted2/224ms10072 KiB
22Accepted2/227ms7824 KiB