알고리즘
백준 23757번 아이들과 선물 상자 C++
영춘권의달인
2022. 12. 20. 12:07
https://www.acmicpc.net/problem/23757
23757번: 아이들과 선물 상자
모든 아이들이 실망하지 않고 각자 원하는 만큼 선물을 가져갈 수 있으면 $1$을, 그렇지 않으면 $0$을 출력한다.
www.acmicpc.net
우선순위 큐 사용
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
priority_queue<int> pq;
int ans = 1;
for (int i = 0; i < n; i++) {
int c;
cin >> c;
pq.push(c);
}
for (int i = 0; i < m; i++) {
int w;
cin >> w;
int top = pq.top();
if (top < w) {
ans = 0;
break;
}
pq.pop();
if (top == w) continue;
pq.push(top - w);
}
cout << ans;
}