Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
You have N balls and K boxes. You want to divide the N balls into K boxes such that:
Determine if it is possible to do so.
For each test case, output YES
if it is possible to divide the N balls into K boxes such that the conditions are satisfied. Otherwise, output NO
.
You may print each character of YES
and NO
in uppercase or lowercase (for example, yes
, yEs
, Yes
will be considered identical).
Input:
4
3 4
30 3
2 2
1 1
Output:
NO
YES
NO
YES
Test Case 1: It is not possible to divide the 3 balls into 4 boxes such that each box contains ≥1 balls.
Test Case 2: One way to divide the 30 balls into 3 boxes is the following: [5,9,16].
Test Case 3: It is not possible to divide the 2 balls into 2 boxes such that no two boxes contain the same number of balls.
Test Case 4: We can divide 1 ball into 1 box.
#include <iostream>
using namespace std;
int main() {
// your code goes here
long long int t,n,k,sum;
cin>>t;
while(t--)
{
cin>>n>>k;
sum=(k*(k+1)/2);
if(sum<=n)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0)
{
int n = in.nextInt();
int k = in.nextInt();
if(n >= ((k*(k+1))/2))
System.out.println("Yes");
else
System.out.println("No");
}
}
}
# cook your dish here
t = int(input())
for _ in range(t):
n,k = map(int,input().split())
if n >= k*(k+1)/2:
print("YES")
else:
print("NO")
In our experience, we suggest you solve this Balls and Boxes CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Balls and Boxes CodeChef Solution
I hope this Balls and Boxes CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>