85862024-01-22 13:08:51IgnácRendező robot (80 pont)cpp17Accepted 80/80231ms37736 KiB
// Source: https://usaco.guide/general/io

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

int main() {
	int n;
	cin >> n;
	map<int, int> a;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		if (a[b - 1] == 0) {
			a[b] = b;
		} else {
			a[b] = a[b - 1];
			a[b - 1] = 0;
		}
	}

	int mini = n * 2;
	for (pair<int, int> sor : a) {
		if (sor.second != 0) {
			int lepes = max(sor.second - 1, n - sor.first) * 2;
			if (sor.second - 1 > n - sor.first) lepes--;
			if (lepes < mini) mini = lepes;
		}
	}

	cout << mini;
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1812 KiB
2Accepted0/03ms2068 KiB
3Accepted2/23ms2224 KiB
4Accepted3/33ms2444 KiB
5Accepted3/33ms2660 KiB
6Accepted2/24ms2836 KiB
7Accepted2/24ms3124 KiB
8Accepted2/24ms3300 KiB
9Accepted2/23ms3216 KiB
10Accepted2/24ms3256 KiB
11Accepted2/24ms3252 KiB
12Accepted2/24ms3420 KiB
13Accepted2/24ms3432 KiB
14Accepted2/24ms3692 KiB
15Accepted2/24ms3804 KiB
16Accepted2/24ms3784 KiB
17Accepted2/24ms3796 KiB
18Accepted4/4231ms23716 KiB
19Accepted4/4231ms24980 KiB
20Accepted4/4182ms26256 KiB
21Accepted4/4221ms27528 KiB
22Accepted4/4166ms28888 KiB
23Accepted4/4156ms30032 KiB
24Accepted4/4187ms31300 KiB
25Accepted4/4222ms32640 KiB
26Accepted4/4152ms33816 KiB
27Accepted4/4197ms35152 KiB
28Accepted4/4158ms36416 KiB
29Accepted4/4152ms37736 KiB