-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDestruction.cpp
More file actions
68 lines (65 loc) · 1.77 KB
/
Copy pathArrayDestruction.cpp
File metadata and controls
68 lines (65 loc) · 1.77 KB
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
// Codeforces Problem: C - Array Destruction
// Link: https://codeforces.com/contest/1474/problem/C
// Status: Accepted Language: C++
#include<iostream>
// #include<bits/stdc++.h>
#include<set>
#include<vector>
// #include<map>
#include<algorithm>
using namespace std;
#define ll long long
#define nl "\n"
#define ws " "
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
int main () {
int t;
cin>>t;
while (t--) {
int n;
cin>>n;
int arr[2 * n];
multiset <int, greater<int>> st;
for (int i = 0; i < 2 * n; i++) {
cin>>arr[i];
st.insert (arr[i]);
}
sort (arr, arr + (2 * n));
bool isEnd = false;
for (int i = 0; i < 2 * n - 1; i++) {
int x = arr[i] + arr[2 * n - 1];
multiset <int, greater<int>> cSt;
cSt = st;
bool f = false;
vector <pair<int, int>> ans;
while (!cSt.empty ()) {
int y = *cSt.begin ();
cSt.erase (cSt.begin ());
int z = x - y;
if (cSt.find (z) != cSt.end ()) {
cSt.erase (cSt.find (z));
ans.push_back ({y, z});
x = max (y, z);
} else {
f = true;
break;
}
}
if (!f && cSt.empty ()) {
cout<<"YES\n"<<arr[2 * n - 1] + arr[i]<<nl;
for (auto p : ans) {
cout<<p.first<<ws<<p.second<<nl;
}
break;
}
if (i == 2 * n - 2) {
isEnd = true;
}
}
if (isEnd) {
cout<<"NO\n";
}
}
return 0;
}