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 ...
Consecutive Sum Riddle Codeforces Solution
Introduction
Codeforces organizes many contests out of which one is this Codeforces rounds to improve coding skills and get a higher coding knowledge. Codeforces Round 747 Div 2 was too a great round to test our coding skills. This round was held on Friday, October 8, 2021 at 20:35UTC+5.5. This round will be rated for coders with rating upto 2100. A total of 6 problems are given which needs to be solved in 2 hours 15 minutes.
The first problem that is Consecutive Sum Riddle was cakewalk it was so simple that in 5 minutes we had more that four thousand successful submissions. Problem B was too a great deal of simplicity but it took a bit of time to understand what to do in the problem. Problem C was medium level and was a good question of logic for the average coders and for best coders it was just too simple. Problem D was good to go but the question was quite difficult to guess what algorithm would be required. Problem E1 was quite simple and many successful submissions were made. Problem E2 and F were the testing the skills of top coders and average coders just kept guessing what algorithms to use.
The contest was a great success and every body enjoyed it truly. Just practice more questions and go ahead in building a streak of code and get better everyday. Happy coding journey ahead.
Question
Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).
You are given an integer . You need to find two integers and such that and
Input
The first line contains a single integer () — the number of test cases.
The first and only line of each test case contains a single integer ().
Output
For each test case, print the two integers and such that and
It can be proven that an answer always exists. If there are multiple answers, print any.
Example
input
Copy
7 1 2 3 6 100 25 3000000000000
output
Copy
0 1 -1 2 1 2 1 3 18 22 -2 7 999999999999 1000000000001
Explanation
This problem is just too simple there are no prerequisites to solve this problem. The problem gets clear when you understand what happens when n =2. This case will give you the idea what to do in this problem. We can solve this sum in many ways out of which I am explaining two ways to do the problem. We can take from -(n-1), -(n-2),....,n which will add to give n as the required sum in the question. We can also take from (-n+1), (-n+2),....,n which also adds up to give n as the sum. These were the two ways in which we could solve the problem; many more ways are still there which will also give the required sum so you can do in that way also. That's it now just code it. I recommend first to do by yourself then if you are stuck have a look at it.
Program Code in C++
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
// your code goes here
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
cout<<-(n-1)<<" "<<n<<endl;
}
return 0;
}
This is the end of the solution hope you enjoyed it and got benefit from it and made your coding journey smooth.
Comments
Post a Comment