forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1354.cpp
More file actions
29 lines (22 loc) · 646 Bytes
/
1354.cpp
File metadata and controls
29 lines (22 loc) · 646 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
class Solution {
public:
bool isPossible(vector<int>& target) {
long sum = 0;
for(auto& t : target)
sum += t;
priority_queue<int> pq(target.begin(), target.end());
int temp;
while(true) {
temp = pq.top();
pq.pop();
sum -= temp;
if(temp == 1 || sum == 1)
return true;
if(temp < sum || sum == 0 || temp % sum == 0)
return false;
temp %= sum;
sum += temp;
pq.push(temp);
}
}
};