PROBLEM LINK:
Practice
Encoding January’20 Contest
Author: shrivas7
Tester: sandeep1103
Editorialist: shrivas7
DIFFICULTY:
EASY
PREREQUISITES:
Basic Mathematics
EXPLANATION:
First step is to check the no. of complete sets of N+M we get within K.Thereafter the job is find out the remaining candies to be bought in order to have K candies in total.
SOLUTIONS:
Setter's Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, m, k, q, l;
cin>>t;
while(t–)
{
cin>>n>>m>>k;
q=k/(n+m) ;
l=q * n+min(n,k-q*(n+m));
cout<<l<<endl;
}
return 0;
}
Tester's Solution
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for( i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for( i=b;i<c;i++)cout<<a[i]<<’ ’
#define ln cout<<‘\n’
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
void solve(){
ll n,i,m,k,j;
cin>>n>>m>>k;
ll s=0;
ll ans=0;
ll q=k/(n+m);
ans=q * n+min(n,k-q*(n+m));
cout<<ans<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”,stdin);
freopen(“op.out”,“w”,stdout);
#endif
int t;
cin>>t;
while(t–)
solve();
}