143242025-01-10 15:34:13sarminVölgy (100 pont)cpp17Wrong answer 55/10045ms1268 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {

	int n; cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a.begin(), a.end());
	auto ut = a[n - 1], utca = a[n - 2];
	int mn = INT_MAX;
	for (int i = min(ut.second, utca.second) + 1; i < max(ut.second, utca.second); i++) {
		mn = min(mn, a[i].first);
	}

	int mx = 0;
	vector<int> maxok;
	for (int i = 0; i < n; i++) {
		if (a[i].first == ut.first) maxok.push_back(a[i].second);
	}
	for (int i = 1; i < (int) maxok.size(); i++) {
		if (maxok[i] - maxok[i - 1] > mx) {
			mx = maxok[i] - maxok[i - 1];
		}
	}

	if (maxok.size() > 1 && mx >= 2) {
		cout << mx;
		return 0;
	}
	
	if (n < 3 || (mn >= ut.first && mn >= utca.first )) {
		cout << -1;
		return 0;
	}
	cout << abs(ut.second - utca.second);
	
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/100
1Accepted0/01ms316 KiB
2Accepted0/02ms316 KiB
3Accepted5/51ms500 KiB
4Accepted5/51ms508 KiB
5Accepted5/51ms316 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Wrong answer0/51ms316 KiB
9Accepted5/51ms316 KiB
10Wrong answer0/51ms316 KiB
11Wrong answer0/53ms316 KiB
12Accepted5/54ms476 KiB
13Wrong answer0/54ms480 KiB
14Wrong answer0/54ms316 KiB
15Accepted5/543ms1192 KiB
16Wrong answer0/545ms1076 KiB
17Accepted5/535ms980 KiB
18Accepted5/539ms1076 KiB
19Accepted5/541ms1268 KiB
20Wrong answer0/541ms1076 KiB
21Wrong answer0/541ms1192 KiB
22Wrong answer0/541ms1076 KiB