# CYBV - Editorial

Practice

Author: Jenish Monpara
Tester: Smit Mandavia

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 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){
}
long long readIntLn(long long l,long long 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;
}

1 Like

Can someone please explain why this solution is correct?

I realized that for input, say n=10 and k=10, answer should be 1 but in my case it was 10 and still solution worked. Am I missing something or there is lack of test cases?

Probably there are no testcases such that n==k
If n is not equal to k the answer will be correct

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
int t;
cin>>t;
while (t–) {
ll n,k;
cin>>n>>k;
if (n==k) {
printf("%lld\n",n);
continue;
}
if (n>k) {
printf(“0\n”);
continue;
}
printf("%lld\n",k/n);
}
return 0;
}

*** bro here you have written n==k
consider n=5 k=5
then one kid will have only one weapon that is minimum weapon=1
so you have to remove this condition

If n=7 and k=19
we can distribute as 2 2 2 2 2 5 4
In this case answer will be 1
Here it is not mentioned we can use only two types of numbers.
Can anyone clear me out here?