Codeforces Round #827 (Div. 4)
You are given three integers , , and . Determine if one of them is the sum of the other two.
The first line contains a single integer () — the number of test cases.
The description of each test case consists of three integers , , ().
For each test case, output "YES" if one of the numbers is the sum of the other two, and "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
71 4 32 5 89 11 200 0 020 20 204 12 315 7 8
YES
NO
YES
YES
NO
NO
YES
In the first test case, .
In the second test case, none of the numbers is the sum of the other two.
In the third test case, .
You are given an array of positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that holds.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the length of the array.
The second line of each test case contains integers () — the elements of the array.
For each test case, output "YES" (without quotes) if the array satisfies the condition, and "NO" (without quotes) otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
341 1 1 158 7 1 3 415
NO
YES
YES
In the first test case any rearrangement will keep the array , which is not strictly increasing.
In the second test case, you can make the array .
On an grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the cells through which it passes.
Determine which color was used last.
The first line of the input contains a single integer () — the number of test cases. The description of test cases follows. There is an empty line before each test case.
Each test case consists of lines, each containing characters. Each of these characters is either 'R', 'B', or '.', denoting a red square, a blue square, and an unpainted square, respectively.
It is guaranteed that the given field is obtained from a colorless one by drawing horizontal red rows and vertical blue columns.
At least one stripe is painted.
For each test case, output 'R' if a red stripe was painted last, and 'B' if a blue stripe was painted last (without quotes).
4....B.......B.......B...RRRRRRRR....B.......B.......B.......B...RRRRRRRBB......BB......BB......BB......BB......BB......BRRRRRRRBRRRRRRBB.B.B..BBRRRRRRBB.B.B..BB.B.B..BBRRRRRRBB.B.B..BB.B.B..BB........................RRRRRRRR................................
R
B
B
R
The first test case is pictured in the statement.
In the second test case, the first blue column is painted first, then the first and last red rows, and finally the last blue column. Since a blue stripe is painted last, the answer is B.
Given an array of positive integers (). Find the maximum value of such that and are coprime, or if no such , exist.
For example consider the array . The maximum value of that can be obtained is , since and are coprime.
Two integers and are coprime if the only positive integer that is a divisor of both of them is (that is, their greatest common divisor is ).
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer () — the length of the array.
The following line contains space-separated positive integers , ,..., () — the elements of the array.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the maximum value of such that and satisfy the condition that and are coprime, or output in case no , satisfy the condition.
633 2 171 3 5 2 4 7 751 2 3 4 532 2 465 4 3 15 12 1651 2 2 3 6
6
12
9
-1
10
7
For the first test case, we can choose , with sum of indices equal to , since and are coprime.
For the second test case, we can choose and , with sum of indices equal to , since and are coprime.
Timur has a stairway with steps. The -th step is meters higher than its predecessor. The first step is meters higher than the ground, and the ground starts at meters.
Timur has questions, each denoted by an integer . For each question , you have to print the maximum possible height Timur can achieve by climbing the steps if his legs are of length . Timur can only climb the -th step if his legs are of length at least . In other words, for each step climbed.
Note that you should answer each question independently.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers () — the number of steps and the number of questions, respectively.
The second line of each test case contains integers () — the height of the steps.
The third line of each test case contains integers () — the numbers for each question.
It is guaranteed that the sum of does not exceed , and the sum of does not exceed .
For each test case, output a single line containing integers, the answer for each question.
Please note, that the answer for some questions won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
34 51 2 1 51 2 4 9 102 21 10 13 11000000000 1000000000 10000000001000000000
1 4 4 9 9
0 2
3000000000
Consider the first test case, pictured in the statement.
- If Timur's legs have length , then he can only climb stair , so the highest he can reach is meter.
- If Timur's legs have length or , then he can only climb stairs , , and , so the highest he can reach is meters.
- If Timur's legs have length or , then he can climb the whole staircase, so the highest he can reach is meters.
Alperen has two strings, and which are both initially equal to "a".
He will perform operations of two types on the given strings:
- — Append the string exactly times at the end of string . In other words, .
- — Append the string exactly times at the end of string . In other words, .
After each operation, determine if it is possible to rearrange the characters of and such that is lexicographically smaller than .
Note that the strings change after performing each operation and don't go back to their initial states.
Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. A formal definition is as follows: string is lexicographically smaller than string if there exists a position such that , and for all , . If no such exists, then is lexicographically smaller than if the length of is less than the length of . For example, and , where we write if is lexicographically smaller than .
The first line of the input contains an integer () — the number of test cases.
The first line of each test case contains an integer — the number of operations Alperen will perform.
Then lines follow, each containing two positive integers and (; ) and a non-empty string consisting of lowercase English letters — the type of the operation, the number of times we will append string and the string we need to append respectively.
It is guaranteed that the sum of over all test cases doesn't exceed and that the sum of lengths of all strings in the input doesn't exceed .
For each operation, output "YES", if it is possible to arrange the elements in both strings in such a way that is lexicographically smaller than and "NO" otherwise.
352 1 aa1 2 a2 3 a1 2 b2 3 abca21 5 mihai2 2 buiucani31 5 b2 3 a2 4 paiu
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
In the first test case, the strings are initially "a" and "a".
After the first operation the string becomes "aaa". Since "a" is already lexicographically smaller than "aaa", the answer for this operation should be "YES".
After the second operation string becomes "aaa", and since is also equal to "aaa", we can't arrange in any way such that it is lexicographically smaller than , so the answer is "NO".
After the third operation string becomes "aaaaaa" and is already lexicographically smaller than it so the answer is "YES".
After the fourth operation becomes "aaabb" and there is no way to make it lexicographically smaller than "aaaaaa" so the answer is "NO".
After the fifth operation the string becomes "aaaaaaabcaabcaabca", and we can rearrange the strings to: "bbaaa" and "caaaaaabcaabcaabaa" so that is lexicographically smaller than , so we should answer "YES".
You are given an array consisting of nonnegative integers.
Let's define the prefix OR array as the array , where represents the bitwise OR operation. In other words, the array is formed by computing the of every prefix of .
You are asked to rearrange the elements of the array in such a way that its prefix OR array is lexicographically maximum.
An array is lexicographically greater than an array if in the first position where and differ, .
The first line of the input contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () — the length of the array .
The second line of each test case contains nonnegative integers ().
It is guaranteed that the sum of over all test cases does not exceed .
For each test case print integers — any rearrangement of the array that obtains the lexicographically maximum prefix OR array.
541 2 4 875 1 2 3 4 5 521 10162 3 4 2 3 481 4 2 3 4 5 7 1
8 4 2 1
5 2 1 3 4 5 5
101 1
4 3 2 2 3 4
7 1 4 2 3 4 5 1
Comments
Post a Comment