-
Notifications
You must be signed in to change notification settings - Fork 0
/
B_Transfusion.cpp
53 lines (52 loc) · 1.04 KB
/
B_Transfusion.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
// Date: 06-12-2024 at 21:18 BST
// Link: https://codeforces.com/contest/2050/problem/B
#include <bits/stdc++.h>
#define null nullptr
#define ll long long int
#define nl '\n'
using namespace std;
/* author @MullaRohan */
void solve()
{
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
ll sum = accumulate(v.begin(), v.end(), 0LL);
if (sum % n != 0)
{
cout << "NO" << nl;
return;
}
ll evenSum = 0, oddSum = 0;
int even = 0, odd = 0;
for (int i = 0; i < n; i += 2)
{
evenSum += v[i];
even++;
}
for (int i = 1; i < n; i += 2)
{
oddSum += v[i];
odd++;
}
if ((evenSum / even == sum / n) && (oddSum / odd == sum / n))
{
cout << "YES" << nl;
}
else
cout << "NO" << nl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int test;
cin >> test;
while (test--)
{
solve();
}
return 0;
}