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++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. map<int,int>mp ;
  10. while (t--) {
  11. int n, x;
  12. cin >> n >> x;
  13. if (n == 1) {
  14. mp[x]++;
  15. } else {
  16. int i = 29;
  17. while (i >= 0) {
  18. if (mp[i]) {
  19. int k = x / pow(2, i);
  20. int v = min(k, mp[i]);
  21. x -= (v * pow(2, i));
  22. }
  23. i--;
  24. }
  25.  
  26. if (x == 0) {
  27. cout << "YES\n";
  28. } else {
  29. cout << "NO\n";
  30. }
  31. }
  32. }
  33. return 0;
  34. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.