[Solution] Make Nonzero Sum (easy version) Codeforces Solution
This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.
You are given an array consisting of integers and . You have to build a partition of this array into the set of segments with the following property:
- Denote the alternating sum of all elements of the -th segment as : = . For example, the alternating sum of elements of segment in array equals to .
- The sum of over all segments of partition should be equal to zero.
Note that each does not have to be equal to zero, this property is about sum of over all segments of partition.
The set of segments is called a partition of the array of length if and for all . In other words, each element of the array must belong to exactly one segment.
You have to build a partition of the given array with properties described above or determine that such partition does not exist.
Note that it is not required to minimize the number of segments in the partition.
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains an integer () — the length of the array .
The second line of each test case contains integers ( is or ) — the elements of the given array.
It's guaranteed that the sum of over all test cases does not exceed .
For each test case, if required partition does not exist, print . Otherwise, print an integer — the number of segments in the partition.
Then in the -th of the following lines print two integers and — description of the -th segment. The following conditions should be satisfied:
- for each from to .
- for each from to .
- .
If there are multiple correct partitions of the array, print any of them.
In the first test case we can build a partition of one segment of length . The sum of this segment will be equal to .
In the second test case we can build a partition of two segments of length . The sum of the first segment will be equal to , and the sum of the second segment: . So, the total sum will be equal to .
In the third and in the fourth test cases it can be proved that there are no required partition.
No comments:
Post a Comment