hpnq

Untitled

May 5th, 2022
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4.  
  5. ll n, a, b, c;
  6. int main()
  7. {
  8.     cin >> n >> a >> b >> c ;
  9.     while( a + b + c > 0 and n != 0)
  10.     {
  11.         if(a != 0)
  12.         {
  13.             a--;
  14.             n = n/2;
  15.         }else
  16.         {
  17.             if(n%2 == 0)
  18.             {
  19.                 if(b != 0)
  20.                 {
  21.                     b--;
  22.                     n = (n+1)/2;
  23.                 }else if(c!=0)
  24.                 {
  25.                     c--;
  26.                     n = (n-1)/2;
  27.                 }
  28.             }else
  29.             {
  30.                 if(c!=0)
  31.                 {
  32.                     c--;
  33.                     n = (n-1)/2;
  34.                 }else if(b != 0)
  35.                 {
  36.                     b--;
  37.                     n = (n+1)/2;
  38.                 }
  39.             }
  40.         }
  41.  
  42.     }
  43.     cout << n;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment