前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces Round #615 (Div. 3)A. Collecting Coins

Codeforces Round #615 (Div. 3)A. Collecting Coins

作者头像
glm233
发布2020-09-28 11:10:02
5600
发布2020-09-28 11:10:02
举报
文章被收录于专栏:glm的全栈学习之路

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 aa coins, Barbara has bb coins and Cerene has cc coins. Recently Polycarp has returned from the trip around the world and brought nn coins.

He wants to distribute all these nn 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 AA coins to Alice, BB coins to Barbara and CC coins to Cerene (A+B+C=nA+B+C=n), then a+A=b+B=c+Ca+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 nn coins between sisters in a way described above.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The next tt lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a,b,ca,b,c and nn (1≤a,b,c,n≤1081≤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 nn coins between his sisters and "NO" otherwise.

Example

input

Copy

代码语言:javascript
复制
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3

output

Copy

代码语言:javascript
复制
YES
YES
NO
NO
YES

题目链接:https://codeforces.com/contest/1294/problem/A

题意:

你有三个姐妹她们分别有 a , b , c枚硬币,你有n枚,你可以把硬币随意分给她们(必须分完),使她们的硬币数A = B = C

第一题一般是简单的数学推导:

设分别分给三个姐妹x,y,z

有a+x=b+y=c+z,即a+x+b+y+c+z=3*(a+x)=3*(b+y)=3*(c+z)=a+b+c+n

可以求出x=(a+b+c+n-3*a)/3,y=x=(a+b+c+n-3*b)/3,z=(a+b+c+n-3*c)/3,如果三个式子的分母只要有一个小于零或者不能被3整除就不能分完,否则可以

代码语言:javascript
复制
#include<bits/stdc++.h>
#define ll long long
#define rg register ll
using namespace std;
ll n,t,a,b,c;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c>>n;
        ll k1=(a+b+c+n-3*a)/3,k2=(a+b+c+n-3*b)/3,k3=(a+b+c+n-3*c)/3;
        ll flag=0;
        //cout<<k1<<" "<<k2<<" "<<k3<<endl;
        if(a+b+c+n-3*a<0)flag=1;
        if(a+b+c+n-3*b<0)flag=1;
        if(a+b+c+n-3*c<0)flag=1;
        if(k1*3!=a+b+c+n-3*a)flag=1;
        if(k2*3!=a+b+c+n-3*b)flag=1;
        if(k3*3!=a+b+c+n-3*c)flag=1;
        !flag?cout<<"YES"<<endl:cout<<"NO"<<endl;
    }
    while(1)getchar();
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/01/24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目链接:https://codeforces.com/contest/1294/problem/A
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档