Advertisement
Goga21

Untitled

Mar 28th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | Source Code | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. signed main(){
  8.     int t;
  9.     cin >> t;
  10.     while(t--) {
  11.         int a, b, c;
  12.         cin >> a >> b >> c;
  13.         if(c == 0){
  14.             cout << -1 << '\n';
  15.         }else if(a == 0){
  16.             if(b == 0 && c == 1){
  17.                 cout << 0 << '\n';
  18.             }else if(b > 0 && c == 1){
  19.                 cout << b << '\n';
  20.             }else{
  21.                 cout << -1 << '\n';
  22.             }
  23.         }else if(b == 0){
  24.             if(a + 1 == c){
  25.                 cout << a << '\n';
  26.             }else{
  27.                 cout << -1 << '\n';
  28.             }
  29.         }else{
  30.             if(a + 1 == c){
  31.                 if(b == 1){
  32.                     cout << a << '\n';
  33.                 }else {
  34.                     int h = 1, floor = 1;
  35.                     while (true) {
  36.                         if (a - floor >= 0) {
  37.                             a -= floor;
  38.                             floor *= 2;
  39.                             h++;
  40.                         } else {
  41.                             break;
  42.                         }
  43.                     }
  44.                     b = b - (floor - a);
  45.                     while (true) {
  46.                         b -= floor;
  47.                         h++;
  48.                         if (b < 0) {
  49.                             break;
  50.                         }
  51.                     }
  52.                     cout << h << '\n';
  53.                 }
  54.             }else{
  55.                 cout << -1 << '\n';
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement