89032024-02-03 18:31:50IgnácLegtöbbször szomszédok (75 pont)cpp17Time limit exceeded 63/75300ms6428 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	map<int, vector<int>> a;
	map<int, int> dbe, dbm;
	for (int i = 1; i <= m - 1; i++) {
		int pont;
		cin >> pont;
		a[pont].push_back(i);
	}

	int p;
	cin >> p;
	int laste = 100001, lastm = 0;
	for (pair<int, vector<int>> lo : a) {
		if (lo.first > p && laste == 100001) laste = lo.first;
		if (lo.first < p) lastm = lo.first;
	}

	for (int lo : a[laste]) {
		dbe[lo]++;
	}

	for (int lo : a[lastm]) {
		dbm[lo]++;
	}

	vector<int> ee = a[laste], mm = a[lastm];
	for (int i = m + 1; i <= n; i++) {
		int pont;
		cin >> pont;
		if (pont == laste) ee.push_back(i);
		if (pont == lastm) mm.push_back(i);
		if (pont < laste && pont > p) {
			ee = {i};
			laste = pont;
		}

		if (pont > lastm && pont < p) {
			mm = {i};
			lastm = pont;
		}
		for (int lo : ee) dbe[lo]++;
		for (int lo : mm) dbm[lo]++;
	}

	int be = -1;
	for (pair<int, int> lo : dbe) {
		if (lo.second > dbe[be]) be = lo.first;
	}

	if (be == -1) cout << "-1\n";
	else cout << be << " " << dbe[be] << "\n";

	int bm = -1;
	for (pair<int, int> lo : dbm) {
		if (lo.second > dbm[bm]) bm = lo.first;
	}

	if (bm == -1) cout << "-1\n";
	else cout << bm << " " << dbm[bm] << "\n";
}
SubtaskSumTestVerdictTimeMemory
base63/75
1Accepted0/03ms1832 KiB
2Accepted0/0163ms2316 KiB
3Accepted2/23ms2492 KiB
4Accepted2/23ms2448 KiB
5Accepted4/43ms2416 KiB
6Accepted4/43ms2416 KiB
7Accepted3/33ms2660 KiB
8Accepted4/43ms2780 KiB
9Accepted4/47ms3612 KiB
10Accepted4/44ms2636 KiB
11Accepted4/44ms2768 KiB
12Accepted4/48ms2804 KiB
13Accepted4/48ms2812 KiB
14Accepted4/48ms2940 KiB
15Accepted4/48ms3152 KiB
16Accepted4/412ms3232 KiB
17Accepted4/414ms3360 KiB
18Accepted4/419ms3608 KiB
19Time limit exceeded0/4300ms4084 KiB
20Time limit exceeded0/4248ms4260 KiB
21Time limit exceeded0/4268ms4444 KiB
22Accepted4/446ms6428 KiB