-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1512D.cpp
More file actions
executable file
·58 lines (51 loc) · 972 Bytes
/
Copy path1512D.cpp
File metadata and controls
executable file
·58 lines (51 loc) · 972 Bytes
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
/*
Problem Code: 1512D
Time: O(n)
Space: O(n)
Author: Mohammed Shoaib, github.com/Mohammed-Shoaib
*/
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
void corrupted_array(int n, vector<int>& b) {
int64_t sum = accumulate(b.begin(), b.end(), 0LL);
vector<int> a;
nth_element(b.begin(), b.begin() + 1, b.end(), greater<int>());
sum -= b[0];
for (int i = 1; i < n + 2; i++) {
if (sum - b[i] != b[0])
continue;
for (int j = 1; j < n + 2; j++)
if (i != j)
a.push_back(b[j]);
break;
}
sum += b[0];
if (a.empty()) {
sum = accumulate(b.begin() + 2, b.end(), 0LL);
if (sum != b[1])
a.push_back(-1);
else {
for (int i = 2; i < n + 2; i++)
a.push_back(b[i]);
}
}
for (int& x: a)
cout << x << " ";
cout << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> b(n + 2);
for (int& x: b)
cin >> x;
corrupted_array(n, b);
}
return 0;
}