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 ...
Diagonal Movement CodeChef Starters 14 Solution
Question
Given the coordinates of a point in 2-D plane. Find if it is possible to reach from . The only possible moves from any coordinate are as follows:
- Go to the point with coordinates
- Go to the point with coordinates
- Go to the point with coordinates
- Go to the point with coordinates
Input
- First line will contain , number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, two integers
Output
For each test case, print YES
if it is possible to reach from , otherwise print NO
.
You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
Constraints
Sample Input
6
0 2
1 2
-1 -3
-1 0
-3 1
2 -1
Sample Output
YES
NO
YES
NO
YES
NO
Explanation
Test case : A valid sequence of moves can be: .
Test case : There is no possible way to reach the point from .
Test case : A valid sequence of moves can be:
Explanation
This question is just a cakewalk we don't need to use our brain to much here. We just need to check whether the sum of the two inputs is even or not if it is even then print yes otherwise print no. There is no logic used in this question we just observe this pattern by test cases given in the problem. So guys good luck for more contest like this, happy coding journey ahead.
Program Code in C++
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll const N = 1e6;
int main()
{
int t;
cin >> t;
while (t--)
{
ll x,y;
cin>>x>>y;
ll s=x+y;
if(s%2==0)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
Comments
Post a Comment