Answer to Question #171467 in C++ for joy

Question #171467

During the exam she have to go into the magic room N times. Initially there are X magic items in the room. Before each visit she can use magic to decrease the number of magic items in the room. For each item she spends 1 mana point to destroy it. After each visit the number of magic items increases by 2 times. She can't go into room if there are more than L magic items in it. What minimum mana points does Kate need to pass the exam?

You need to solve this problem for several test cases.

INPUT

The first line of input contains single integer T (1≤T≤105) - a number of test cases.

Then follow T lines. The i-th of these lines contains three integers Xi, Li and Ni (0≤Xi,Li,Ni≤1018).

OUTPUT

Print T lines.

The i-th of them should contain single integer - minimum number of mana points needed to pass the exam in the i-th test case.

Sample Input

2
2 5 3
6 5 0

Sample Output

1
0
1
Expert's answer
2021-03-14T01:01:16-0500
#include <bits/stdc++.h>
using namespace std;
int main()
{
    
    int num,x,l,n,count;
    
    cin>>num;
    
    for (int i = 0; i<num; i++)
    {
        cin>>x>>l>>n;
        for (int i = 0; i<n; i++)
        {
            count  = 0;
            if (x < l)
            {
                x = x * 2;
            }
            else
            {
                x = x - l;
                count += 1;
                cout<<count<<endl;
            }
        }
    }
    if (n == 0)
    {
        cout<<"0"<<endl;
    }

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS