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
| #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
int n;
struct Node {
int r1, r2, r3;
};
vector<Node> res;
unordered_map<int, int> mp;
priority_queue<PII> heap;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x; scanf("%d", &x);
mp[x]++;
}
for (auto item : mp) heap.push({item.second, item.first});
int cnt = 0;
while (heap.size() >= 3) {
auto a = heap.top(); heap.pop();
auto b = heap.top(); heap.pop();
auto c = heap.top(); heap.pop();
int ra = a.second, rb = b.second, rc = c.second;
int t[3] = {ra, rb, rc};
sort(t, t + 3);
res.push_back({t[2], t[1], t[0]});
cnt++;
if (--a.first) heap.push(a);
if (--b.first) heap.push(b);
if (--c.first) heap.push(c);
}
cout << cnt << endl;
for (auto x : res) printf("%d %d %d\n", x.r1, x.r2, x.r3);
return 0;
}
|