-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteTwoElements.cpp
More file actions
50 lines (47 loc) · 1.09 KB
/
Copy pathDeleteTwoElements.cpp
File metadata and controls
50 lines (47 loc) · 1.09 KB
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
// Codeforces Problem: C - Delete Two Elements
// Link: https://codeforces.com/contest/1598/problem/C
// Status: Accepted Language: C++
#include<iostream>
// #include<bits/stdc++.h>
// #include<set>
// #include<vector>
#include<map>
// #include<algorithm>
using namespace std;
#define ll long long
#define nl "\n"
#define ws " "
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
int main () {
int t;
cin>>t;
while (t--) {
int n;
cin>>n;
int arr[n];
map <int, int> mp;
ll sum = 0;
for (int i = 0; i < n; i++) {
cin>>arr[i];
mp[arr[i]]++;
sum += arr[i];
}
if ((sum * 2) % n != 0) {
cout<<0<<nl;
continue;
}
ll tot = (sum * 2) / n, ans = 0;
for (int i = 0; i < n; i++) {
int a = tot - arr[i];
if (mp.count (a)) {
ans += mp[a];
}
if (arr[i] == a) {
ans -= 1;
}
}
cout<<ans / 2<<nl;
}
return 0;
}