CF1512D.Corrupted Array
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a number n and an array b1,b2,…,bn+2, obtained according to the following algorithm:
- some array a1,a2,…,an was guessed;
- array a was written to array b, i.e. bi=ai (1≤i≤n);
- The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. bn+1=a1+a2+…+an;
- The (n+2)-th element of the array b was written some number x (1≤x≤109), i.e. bn+2=x; The
- array b was shuffled.
For example, the array b=[2,3,7,12,2] it could be obtained in the following ways:
- a=[2,2,3] and x=12;
- a=[3,2,7] and x=2.
For the given array b, find any array a that could have been guessed initially.
给你一个数字 n 和一个数组 b1,b2,…,bn+2,该数组是按如下算法生成的:
- 猜测了某个数组 a1,a2,…,an;
- 将数组 a 写入数组 b,即 bi=ai(1≤i≤n);
- 数组 b 的第 (n+1) 个元素是数组 a 中所有数的和,即 bn+1=a1+a2+…+an;
- 数组 b 的第 (n+2) 个元素被写入某个数 x(1≤x≤109),即 bn+2=x;
- 数组 b 被打乱顺序(即进行了随机重排)。
例如,数组 b=[2,3,7,12,2] 可能通过以下方式得到:
- a=[2,2,3] 且 x=12;
- a=[3,2,7] 且 x=2。
对于给定的数组 b,找出任意一个可能最初被猜测的数组 a。
输入格式
The first line contains a single integer t (1≤t≤104). Then t test cases follow.
The first line of each test case contains a single integer n (1≤n≤2⋅105).
The second row of each test case contains n+2 integers b1,b2,…,bn+2 (1≤bi≤109).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)。随后是 t 组测试数据。
每组测试数据的第一行包含一个整数 n(1≤n≤2⋅105)。
每组测试数据的第二行包含 n+2 个整数 b1,b2,…,bn+2(1≤bi≤109)。
保证所有测试数据的 n 之和不超过 2⋅105。
输出格式
For each test case, output:
- "-1", if the array b could not be obtained from any array a;
- n integers a1,a2,…,an, otherwise.
If there are several arrays of a, you can output any.
对于每个测试用例,输出:
- 若不存在任何数组 a 能够得到数组 b,则输出
\-1; - 否则输出 n 个整数 a1,a2,…,an。
若存在多个满足条件的数组 a,输出任意一个即可。
输入输出样例
输入#1
4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1
输出#1
2 3 7 -1 2 2 2 3 9 1 2 6
输入解题思路,AI测评打分。不知道怎么写?