-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcoci14c4p2.cpp
54 lines (48 loc) · 1.52 KB
/
coci14c4p2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Ivan Carvalho
// Solution to https://dmoj.ca/problem/coci14c4p2
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int main() {
map<int, int> frequencias;
deque<ii> sequencia;
int N, vez = 0;
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
int x;
scanf("%d", &x);
frequencias[x]++;
}
for (map<int, int>::iterator it = frequencias.begin();
it != frequencias.end(); it++) {
sequencia.push_back(*it);
}
while (sequencia.size() > 3) {
int minimo = min(sequencia.front().second, sequencia.back().second);
sequencia.front().second -= minimo;
sequencia[1].second += minimo;
sequencia.back().second -= minimo;
sequencia[sequencia.size() - 2].second += minimo;
if (sequencia.front().second == 0) sequencia.pop_front();
if (sequencia.back().second == 0) sequencia.pop_back();
}
while (sequencia.size() == 3) {
if (vez == 0) {
vez ^= 1;
sequencia.front().second -= 1;
sequencia[1].second += 1;
if (sequencia.front().second == 0) sequencia.pop_front();
} else {
vez ^= 1;
sequencia.back().second -= 1;
sequencia[sequencia.size() - 2].second += 1;
if (sequencia.back().second == 0) sequencia.pop_back();
}
}
if (vez == 0)
printf("Slavko\n");
else
printf("Mirko\n");
printf("%d %d\n", sequencia.front().first, sequencia.back().first);
return 0;
}