149422025-02-09 10:21:14sarminLegtöbbször szomszédok (75 pont)cpp17Partially correct 73/7518ms1332 KiB
// Legtöbbször szomszédok
// Created by Armin on 2/8/2025.

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<int, int>;
using vi = vector<int>;
using v = vector<int>;
using vvi = vector<vector<int>>;
using vpi = vector<pair<int, int>>;
using vl = vector<ll>;
constexpr ll MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    int n, m; cin >> n >> m;
    map<int, int> elott, utan;
    vpi v;
	set<int> volt;
	int en = 0;
    for (int i = 0; i < m; i++) {
    	int x; cin >> x;
    	if (i + 1 == m) en = x;
    	if (volt.find(x) != volt.end()) continue;
    	v.push_back({x, i + 1});
    	volt.insert(x);
    }
	sort(v.begin(), v.end());
	int maxelott = 0, maxekul = INT_MAX, maxutan = 0, maxutkul = INT_MAX;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].first == en) {
			//cout << "Talált: " << v[i].first << " " << v[i].second << "\n";
			if (i - 1 >= 0) {
				maxutan = v[i - 1].second;
				maxutkul = abs(v[i].first - v[i - 1].first);
				utan[maxutan]++;
				//cout << v[i - 1].first << "\n";
			}
			if (i + 1 < v.size()) {
				maxelott = v[i + 1].second;
				maxekul = abs(v[i].first - v[i + 1].first);
				elott[maxelott]++;
				//cout << v[i + 1].first << "\n";
			}
			break;
		}
	}
	//cout << "en: " << en << "\n";
	// cout << "E: " << maxelott << " " << maxutan << " " << en << "\n";
	// cout << "E: " << maxekul << " " << maxutkul << "\n";
	for (int i = m; i < n; i++) {
		int x; cin >> x;
		//cout <<"x: " << x << "\n";
		if (x > en && abs(en - x) < maxekul) {
			maxelott = i + 1;
			//cout << maxelott << " (elott) ";
			maxekul = abs(en - x);
			elott[maxelott]++;
		} else {
			elott[maxelott]++;
			// cout << maxelott << " " << elott[maxelott] <<  " (elott2) ";
		}
		if (x < en && abs(en - x) < maxutkul) {
			maxutan = i + 1;
			//cout << maxutan << " (utan) ";
			maxutkul = abs(en - x);
			utan[maxutan]++;
		} else {
			utan[maxutan]++;
			// cout << maxutan << " (utan2) ";
		}
		// cout << "\n";
	}

	int mx1 = 0, val1 = -1;
	for (auto& [ki, mi] : utan) {
		if (mi > mx1) {
			mx1 = mi;
			val1 = ki;
		}
	}

	int mx2 = 0, val2 = -1;
	for (auto& [ki, mi] : elott) {
		if (mi > mx2) {
			mx2 = mi;
			val2 = ki;
		}
	}
	if (val2 == -1) {
		cout << "-1\n";
	} else {
		cout << val2 << " " << mx2 << "\n";
	}

	if (val1 == -1) {
		cout << "-1\n";
	} else {
		cout << val1 << " " << mx1 << "\n";
	}
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base73/75
1Accepted0/01ms508 KiB
2Accepted0/012ms820 KiB
3Partially correct1/21ms316 KiB
4Partially correct1/21ms316 KiB
5Accepted4/41ms388 KiB
6Accepted4/41ms368 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/44ms564 KiB
10Accepted4/42ms328 KiB
11Accepted4/42ms316 KiB
12Accepted4/43ms388 KiB
13Accepted4/43ms316 KiB
14Accepted4/43ms444 KiB
15Accepted4/43ms436 KiB
16Accepted4/44ms564 KiB
17Accepted4/46ms564 KiB
18Accepted4/47ms564 KiB
19Accepted4/412ms564 KiB
20Accepted4/410ms564 KiB
21Accepted4/410ms664 KiB
22Accepted4/418ms1332 KiB