Equal Beauty CodeChef SnackDown 2021 Round 1A Question The beauty of an (non-empty) array of integers is defined as the difference between its largest and smallest element. For example, the beauty of the array [2,3,4,4,6] is 6−2=4. An array A is said to be good if it is possible to partition the elements of A into two non-empty arrays B1 and B2 such that B1 and B2 have the same beauty. Each element of array A should be in exactly one array: either in B1 or in B2. For example, the array [6,2,4,4,4] is good because its elements can be partitioned into two arrays B1=[6,4,4] and B2=[2,4], where both B1 and B2 have the same beauty (6−4=4−2=2). You are given an array A of length N. In one move you can: Select an index i (1≤i≤N) and either increase Ai by 1 or decrease Ai by 1. Find the minimum number of moves required to make the array A good. Input Format The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow. Each ...
RCB and Playoffs CodeChef Starters 14 Solution
Question
Team RCB has earned points in the games it has played so far in this year's IPL. To qualify for the playoffs they must earn at least a total of points. They currently have games left, in each game they earn points for a win, point for a draw, and no points for a loss.
Is it possible for RCB to qualify for the playoffs this year?
- First line will contain , number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, three integers
For each test case, output in one line YES if it is possible for RCB to qualify for the playoffs, or NO if it is not possible to do so.
Output is case insensitive, which means that "yes", "Yes", "YEs", "no", "nO" - all such strings will be acceptable.
Input
34 10 83 6 1 4 8 2
Output:YESNOYES
Explanation
This question is a cake walk, we just need to do few things to get the correct solution. We just need to check whether the third input of one test case is greater than the difference of the second input and first input of the test case, if it is then print no else print yes. Nothing more to do in this question.Program Code
#include <bits/stdc++.h>using namespace std;
int main() { int t; cin>>t; while(t--){ int x,y,z; cin>>x>>y>>z; if(2*z<(y-x)) cout<<"NO"<<endl; else { cout<<"YES"<<endl; } } return 0;}
For each test case, output in one line YES if it is possible for RCB to qualify for the playoffs, or NO if it is not possible to do so.
Output is case insensitive, which means that "yes", "Yes", "YEs", "no", "nO" - all such strings will be acceptable.
Input
3
4 10 8
3 6 1
4 8 2
YES
NO
YES
Explanation
This question is a cake walk, we just need to do few things to get the correct solution. We just need to check whether the third input of one test case is greater than the difference of the second input and first input of the test case, if it is then print no else print yes. Nothing more to do in this question.
Program Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int x,y,z;
cin>>x>>y>>z;
if(2*z<(y-x))
cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
}
}
return 0;
}
Comments
Post a Comment