89052024-02-03 18:42:32IgnácLegtöbbször szomszédok (75 pont)cpp17Accepted 75/7556ms14372 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];
	int ie = m, im = m;
	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) {
			for (int lo : ee) dbe[lo] += i - ie;
			ie = i;
			ee = {i};
			laste = pont;
		}

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

	for (int lo : ee) dbe[lo] += n + 1 - ie;
	for (int lo : mm) dbm[lo] += n + 1 - im;
	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
base75/75
1Accepted0/03ms1808 KiB
2Accepted0/028ms2492 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2516 KiB
5Accepted4/43ms2756 KiB
6Accepted4/43ms2920 KiB
7Accepted3/33ms2996 KiB
8Accepted4/43ms2964 KiB
9Accepted4/47ms3836 KiB
10Accepted4/44ms3064 KiB
11Accepted4/44ms3312 KiB
12Accepted4/48ms3364 KiB
13Accepted4/48ms3364 KiB
14Accepted4/48ms3492 KiB
15Accepted4/48ms3708 KiB
16Accepted4/410ms3784 KiB
17Accepted4/414ms3788 KiB
18Accepted4/417ms3916 KiB
19Accepted4/456ms14172 KiB
20Accepted4/454ms14100 KiB
21Accepted4/454ms14372 KiB
22Accepted4/441ms6572 KiB