Problem:
A. Vasya and Chocolate
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There is a special offer in Vasya's favourite supermarket: if the customer buys chocolate bars, he or she may take additional bars for free. This special offer can be used any number of times.
Vasya currently has roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!
Input
The first line contains one integer () — the number of testcases.
Each of the next lines contains four integers — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.
Output
Print lines. -th line should contain the maximum possible number of chocolate bars Vasya can get in -th test.
Example
input
Copy
2 10 3 1 1 1000000000 1 1000000000 1
output
Copy
13 1000000001000000000
Note
In the first test of the example Vasya can buy bars, get for free, buy another bar, and so he will get bars.
In the second test Vasya buys bars and gets for free. So he has bars.
Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ar[4];
for(int i=0;i<3;i++)
cin>>ar[i];
sort(ar,ar+3);
int aa=ar[0]+ar[1];
if(aa>ar[2])
cout<<0<<endl;
else
cout<<ar[2]-aa+1<<endl;
return 0;
}
No comments:
Post a Comment