Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isPossible(vector<int>& target) {
- std:priority_queue<int> pq;
- long long sum = 0;
- for (int i = 0; i < target.size(); ++i) {
- pq.push(target[i]);
- sum += target[i];
- }
- //std::cout << sum << std::endl;
- while(pq.top() != 1) {
- int maxim = pq.top();
- int value = maxim - (sum - maxim);
- if (value <= 0 ) {
- return false;
- }
- pq.pop(); pq.push(value);
- sum = (long long)maxim;
- }
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement