CodeForces - 1618A Polycarp and Sums of Subsequences

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1618A Polycarp and Sums of Subsequences相关的知识,希望对你有一定的参考价值。

A. Polycarp and Sums of Subsequences
time limit per test1 second
memory limit per test256 megabytes

Polycarp had an array a of 3 positive integers. He wrote out the sums of all non-empty subsequences of this array, sorted them in non-decreasing order, and got an array b of 7 integers.

For example, if a=1,4,3, then Polycarp wrote out 1, 4, 3, 1+4=5, 1+3=4, 4+3=7, 1+4+3=8. After sorting, he got an array b=1,3,4,4,5,7,8.
Unfortunately, Polycarp lost the array a. He only has the array b left. Help him to restore the array a.

Input
The first line contains one integer t (1≤t≤5000) — the number of test cases.

Each test case consists of one line which contains 7 integers b1,b2,…,b7 (1≤bi≤109; bi≤bi+1).

Additional constraint on the input: there exists at least one array a which yields this array b as described in the statement.

Output
For each test case, print 3 integers — a1, a2 and a3. If there can be several answers, print any of them.

Example
input
5
1 3 4 4 5 7 8
1 2 3 4 5 6 7
300000000 300000000 300000000 600000000 600000000 600000000 900000000
1 1 2 999999998 999999999 999999999 1000000000
1 2 2 3 3 4 5
output
1 4 3
4 1 2
300000000 300000000 300000000
999999998 1 1
1 2 2

Note
The subsequence of the array a is a sequence that can be obtained from a by removing zero or more of its elements.

Two subsequences are considered different if index sets of elements included in them are different. That is, the values of the elements don’t matter in the comparison of subsequences. In particular, any array of length 3 has exactly 7 different non-empty subsequences.

问题链接CodeForces - 1618A Polycarp and Sums of Subsequences
问题简述:有3个正整数a、b和c。把a, b, c, a + b, a + c, b + c, a + b + c从小到大排序,给定这7个数,计算a、b和c。
问题分析:(略)

AC的C++语言程序如下:

/* CodeForces - 1618A Polycarp and Sums of Subsequences */

#include <stdio.h>

#define N 7
int b[N];

int main()

    int t;
    scanf("%d", &t);
    while (t--) 
        for (int i = 0; i < N; i++)
            scanf("%d", &b[i]);

        printf("%d %d %d\\n", b[0], b[1], b[N - 1] - b[0] - b[1]);
    

    return 0;

以上是关于CodeForces - 1618A Polycarp and Sums of Subsequences的主要内容,如果未能解决你的问题,请参考以下文章

codeforces上怎么看测试数据

如何看codeforces做了多少题

codeforces上怎么看测试数据

codeforces比赛后怎么看题解和答案

codeforces是啥?

codeforces Codeforces 650A Watchmen