Header Ad

HackerEarth Picu Bank problem solution

In this HackerEarth Picu Bank problem solution, You have D dollars with you. You want to put it into a Bank, namely Picu Bank. This bank has a peculiar behavior for interest. Regardless of the Bank deposit amount, every month it adds A dollars to your bank account and this continues till M months. Exaxtly on M + 1 months, it adds B dollars (B < A) to your bank account. This scanario repeats again in same manner.( i.e on the (M + 2)th month A dollars are added, and so on.. ). Your task is to find out how many months does it take for the dollar amount to reach at least X, in the bank account.


HackerEarth Picu Bank problem solution


HackerEarth Picu Bank problem solution.

#include<bits/stdc++.h>
#define Y second
#define mpp make_pair
#define nl printf("\n")
#define SZ(x) (int)(x.size())
#define pb(x) push_back(x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define SL(a) scanf("%lld",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define SL2(a,b) scanf("%lld%lld",&a,&b)
#define all(v) v.begin(),v.end()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define fr(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
typedef long long ll;
#define MX 1004
#define inf 10000000000
#define MD 1000000007LL
#define eps 1e-9

ll D,A,M,B,X;
int main() {
int tc,cs=1,q,i,j;
S(tc);
assert(tc<=100000);
assert(tc>=1);
while(tc--){
SL2(D,A);
SL2(M,B);
SL(X);
assert(B<A);
assert(A>=1);
assert(B>=1 && B<=1000000000);
assert(M>=1 && M<=1000000000);
assert(X>=1 && X<=1000000000);
assert(A>=1 && A<=1000000000);
if( X<=D ){
printf("0\n");
continue;
}
X-=D;
ll dd=(M*A+B);
assert(dd>=1);
ll tot=(X/dd);
ll money=tot*dd;
ll ans=(tot*(M+1));
ll rem=X;
if( money )rem=(X%money);
if(rem==0){
printf("%lld\n",ans);
continue;
}
ans+=(ll)(ceil(rem*1.0/A*1.0));
printf("%lld\n",ans);
}
return 0;
}


Post a Comment

0 Comments