forked from isanchez-aguilar/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1144C - Two Shuffled Sequences.cpp
83 lines (64 loc) · 1.05 KB
/
1144C - Two Shuffled Sequences.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* User: Isanchez_Aguilar
* Problem: CodeForces 1144C - Two Shuffled Sequences
*/
#include <bits/stdc++.h>
using namespace std;
using Long = int;
inline void printArray(const vector<Long>& a)
{
cout << a.size() << "\n";
for (int i = 0; i < a.size(); ++i)
cout << (i > 0?" ":"") << a[i];
cout << "\n";
return;
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<Long> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(begin(a), end(a));
vector<Long> x;
vector<Long> y;
bool possible = true;
vector<Long> aux = a;
aux.resize(unique(begin(aux), end(aux)) - begin(aux));
if (aux.size() == n)
x = a;
else
{
for (int i = 2; i < n; ++i)
{
if (a[i - 2] == a[i])
{
possible = false;
break;
}
}
if (possible)
{
for (int i = 0; i < n; ++i)
{
if (i % 2 == 0)
x.push_back(a[i]);
else
y.push_back(a[i]);
}
reverse(begin(y), end(y));
}
}
if (not possible)
cout << "NO\n";
else
{
cout << "YES\n";
printArray(x);
printArray(y);
}
return 0;
}