PROBLEM LINK:
Author: Akash Kumar Bhagat
Tester: Sandeep Singh,Arnab Chanda
Editorialist: Akash Kumar Bhagat
DIFFICULTY:
Easy-Medium
PREREQUISITES:
Maths
PROBLEM:
If someone blows a balloon in X min. After Y balloons he takes rest for Z min. Find the total number of balloons that will be ready after T min.
Note:- Assuming no balloon burst during the entire time.
EXPLANATION:
We know that after Y balloons he person will take rest for Z min, hence time taken to innflate Y balloons is (XY+Z). So he will inflate T/(XY+Z) and the remaining time i.e [T%(XY+Z)] he will inflate [T%(XY+Z)]/X balloons which must be less than Y.
Hence the answer is reduced to a simple formula:
ANS = (T//(X*Y+Z))*Y + min((T%(X*Y+Z))//X,Y)
TIME COMPLEXITY: O(1)
SOLUTIONS:
Python 3.7
for _ in range(int(input())):
x,y,z,t=map(int,input().split())
ans=(t//(x*y+z))*y+min((t%(x*y+z))//x,y)
print(ans)
CPP
#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define ins insert
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define per(i,j,k) for(ll i=j;i>=k;--i)
#define scan(a,n) rep(i,0,n)cin>>a[i]
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define error freopen("error.txt","w",stderr)
#define ff first
#define ss second
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
const int N = 1e6+6;
const int MAX = 20;
const int inf = INT_MAX;
const ll mod = 1e9+7;
const int Log = ceil(log2(MAX))+1;
ll powm(ll a,ll b) {ll res=1LL;while(b) {if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
ll modmult(ll a,ll b) {ll r=0;a%=mod;while(b){if(b&1)r=(r+a)%mod;a=(a<<1)%mod;b>>=1;}return r;}
ll modexpo(ll a,ll b) {ll r=1;a%=mod;while(b){if(b&1)r=(r*a)%mod;a=(a*a)%mod;b>>=1;}return r;}
int32_t main() {
io;
ll t=1;
cin>>t;
while(t--) {
ll x,y,z,h;
cin>>x>>y>>z>>h;
// if(x*y+z>h) {
// cout<<h/(x*y)<<endl;
// continue;
// }
ll block=h/(x*y+z);
ll res=block*y;
res+=min(h%(x*y+z)/x,y);
cout<<res<<endl;
}
return 0;
}