A. Collecting Coins

传送门
A. Collecting Coins
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has three sisters: Alice, Barbara, and Cerene. They’re collecting coins. Currently, Alice has a
coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins. He wants to distribute all these n coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives A coins to Alice, B coins to Barbara and C coins to Cerene (A+B+C=n), then a+A=b+B=c+C Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all n coins between sisters in a way described above. You have to answer t independent test cases.

Input
The first line of the input contains one integer t(1≤t≤104) — the number of test cases.The next t lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a,b,c and n (1≤a,b,c,n≤108) — the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.

Output
For each test case, print “YES” if Polycarp can distribute all n coins between his sisters and “NO” otherwise.

Example
Input

5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3

Output

YES
YES
NO
NO
YES

题意:Polycarp有三个姐妹,分别有a,b,c枚硬币,他带回来n枚硬币,他想把n枚硬币全部分给三个姐妹,使得三个姐妹的硬币数一样多,使她们的硬币数A = B = C 。t个测试样例,每个测试样例给定a,b,c,n。如果能将n枚硬币全部分发出去使得三个姐妹硬币数一样多,输出YES,否则输出NO。

思路:找出三姐妹中硬笔数量最多的,将其他两位数量补为最大值,且补完后剩下硬币数量的能够平分给三姐妹就是对3求余为0则输出YES,否则输出NO

AC代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,a[10];
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d%d%d%d",&a[0],&a[1],&a[2],&n);
        sort(a,a+3);
        int sum=a[2]-a[1]+a[2]-a[0];
        if( n-sum>=0&&(n-sum)%3==0 )
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值