Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main(){
- int t;
- cin >> t;
- while(t--) {
- int a, b, c;
- cin >> a >> b >> c;
- if(c == 0){
- cout << -1 << '\n';
- }else if(a == 0){
- if(b == 0 && c == 1){
- cout << 0 << '\n';
- }else if(b > 0 && c == 1){
- cout << b << '\n';
- }else{
- cout << -1 << '\n';
- }
- }else if(b == 0){
- if(a + 1 == c){
- cout << a << '\n';
- }else{
- cout << -1 << '\n';
- }
- }else{
- if(a + 1 == c){
- if(b == 1){
- cout << a << '\n';
- }else {
- int h = 1, floor = 1;
- while (true) {
- if (a - floor >= 0) {
- a -= floor;
- floor *= 2;
- h++;
- } else {
- break;
- }
- }
- b = b - (floor - a);
- while (true) {
- b -= floor;
- h++;
- if (b < 0) {
- break;
- }
- }
- cout << h << '\n';
- }
- }else{
- cout << -1 << '\n';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement