-
Notifications
You must be signed in to change notification settings - Fork 1
/
1294A.cpp
94 lines (93 loc) · 1.87 KB
/
1294A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
using namespace std;
string coins(int arr[], int tar)
{
int max = arr[0], min = arr[0], mid = arr[0], maxindex = 0, minindex = 0;
if (arr[0] != arr[1] || arr[0] != arr[2])
{
for (int i = 1; i < 3; i++)
{
if (max < arr[i])
{
max = arr[i];
maxindex = i;
}
if (min > arr[i])
{
min = arr[i];
minindex = i;
}
}
for (int i = 1; i < 3; i++)
{
if (i != maxindex && i != minindex)
{
mid = arr[i];
break;
}
}
int dif = max - min;
int dif1 = max - mid;
while (max != min)
{
if (tar - dif >= 0)
{
min += dif;
tar = tar - dif;
}
else
return "NO";
}
while (max != mid)
{
if (tar - dif1 >= 0)
{
mid += dif1;
tar -= dif1;
}
else
return "NO";
}
if (max == min && max == mid)
{
if (tar % 3 == 0 || tar == 0)
{
return "YES";
}
else
return "NO";
}
}
else
{
if (tar % 3 == 0)
{
return "YES";
}
else
return "NO";
}
return "YES";
}
int main(int argc, char const *argv[])
{
int tar = 0;
int t;
cin >> t;
string ans[t];
int in[4];
for (int j = 0; j < t; j++)
{
for (int i = 0; i < 3; i++)
{
cin >> in[i];
}
cin >> tar;
ans[j] = coins(in, tar);
}
for (int i = 0; i < t; i++)
{
cout << ans[i] << "\n";
}
return 0;
}