Educational Codeforces Round 160 (Rated for Div. 2) 1913C - Game with Multiset Solution
Problem Link : https://codeforces.com/problemset/problem/1913/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- map<int,int>mp ;
- while (t--) {
- int n, x;
- cin >> n >> x;
- if (n == 1) {
- mp[x]++;
- } else {
- int i = 29;
- while (i >= 0) {
- if (mp[i]) {
- int k = x / pow(2, i);
- int v = min(k, mp[i]);
- x -= (v * pow(2, i));
- }
- i--;
- }
- if (x == 0) {
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- }
- }
- return 0;
- }
No comments