PROBLEM LINK:
Author: Jenish Monpara
Tester: Smit Mandavia
Editorialist: Aditi Goel
DIFFICULTY:
CAKEWALK
PREREQUISITES:
No prerequisites, simple math
PROBLEM:
We have to distribute K weapons among N kid cyborgs such that the difference between kid cyborg having the maximum weapons and the kid cyborg having minimum weapons should be less than or equal to 1 after distribution of all the weapons. We want to know the minimum number of weapons.
QUICK EXPLANATION:
We can give \frac{K}{N} weapons to each of the kid cyborgs. The remaining K \% N weapons can be given one each to K \% N kids. (\% is the modulo operation)
EXPLANATION:
Firstly, we can notice that we always can distribute K- K \% N (where \% is the modulo operation) weapons evenly between kids, with each kid getting \frac{K}{N} weapons. Now the remaining weapons are K \% N, which can be given 1 to K \% N kids each. Thus, if K\%N is non-zero, the difference between kids with maximum weapons and kid with minimum weapons would be one. Otherwise, it would be 0.
SOLUTIONS:
Setter's Solution
#include <bits/stdc++.h>
#define int long long
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int32_t main()
{
fio;
int t;
cin>>t;
while (t--)
{
int n,k;
cin>>n>>k;
cout<<k/n<<"\n";
}
return 0;
}
Tester's Solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long long readInt(long long l,long long r,char endd){
long long x=0;
int cnt=0;
int fi=-1;
bool is_neg=false;
while(true){
char g=getchar();
if(g==β-β){
assert(fi==-1);
is_neg=true;
continue;
}
if(β0β<=g && g<=β9β){
x*=10;
x+=g-β0β;
if(cnt==0){
fi=g-β0β;
}
cnt++;
assert(fi!=0 || cnt==1);
assert(fi!=0 || is_neg==false);
assert(!(cnt>19 || ( cnt==19 && fi>1) ));
} else if(g==endd){
if(is_neg){
x= -x;
}
assert(l<=x && x<=r);
return x;
} else {
cerr << (int)g << "\n";
assert(false);
}
}
}
string readString(int l,int r,char endd){
string ret=ββ;
int cnt=0;
while(true){
char g=getchar();
assert(g!=-1);
if(g==endd){
break;
}
cnt++;
ret+=g;
}
assert(l<=cnt && cnt<=r);
return ret;
}
long long readIntSp(long long l,long long r){
return readInt(l,r,β β);
}
long long readIntLn(long long l,long long r){
return readInt(l,r,β\nβ);
}
string readStringLn(int l,int r){
return readString(l,r,β\nβ);
}
string readStringSp(int l,int r){
return readString(l,r,β ');
}
int main()
{
ll t,n,q,k,i,j,sum_n,sum_q;
cin >> t;
while(tβ){
cin >> n >> k;
cout << k/n << β\nβ;
}
return 0;
}
Editorialist's Solution
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll t,n,k;
cin>>t;
for(int i = 0; i < t; i++)
{
cin>>n>>k;
cout<<k/n<<endl;
}
return 0;
}