-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLossPermutation.cpp
More file actions
71 lines (69 loc) · 1.83 KB
/
LossPermutation.cpp
File metadata and controls
71 lines (69 loc) · 1.83 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
69
70
//Problem statement link : https://codeforces.com/contest/1759/problem/B
#include <iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
vector<int> v, pv;
int m, s;
cin >> m >> s;
int tmp = 0;
for (int i = 1; i <= m; i++) {
cin >> tmp;
v.push_back(tmp);
}
sort(v.begin(), v.end());
bool alreadyThere = false;
int lastElement = v[m - 1];
for (int i = 1; i < lastElement; i++) {
alreadyThere = false;
for (int j = 0; j < m; j++) {
if (i == v[j]) {
alreadyThere = true;
}
}
if (!alreadyThere) {
pv.push_back(i);
}
}
bool repeated = false;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i != j && v[i]==v[j]) {
repeated = true;
}
}
}
if (repeated) {
cout << "NO\n";
continue;
}
else {
int sumOfRest = 0;
for (int i = 0; i < pv.size(); i++)
sumOfRest += pv[i];
int remSum = s - sumOfRest;
if (remSum == 0)
cout << "YES\n";
else if (remSum >= 0) {
int a = 0;
lastElement = lastElement + 1;
while (a < remSum) {
a = a + lastElement;
lastElement = lastElement + 1;
}
if (a == remSum)
cout << "YES\n";
else
cout << "NO\n";
}
else
cout << "NO\n";
}
}
return 0;
}