-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaverage.cpp
36 lines (36 loc) · 846 Bytes
/
average.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
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{ int n;
scanf("%d",&n);
int a[n];
for(int i=0; i<n; i++)
{ scanf("%d",&a[i]);
}
sort(a, a+n);
long long ans=0;
for(int i=0; i<n; i++)
{ if(i>0 && a[i]==a[i-1])
ans++;
else if(i<n-1 && a[i]==a[i+1])
ans++;
else
{ int left=i, right=i;
while(left>=0 && right<n)
{ if(a[left]+a[right]==2*a[i] && (left!=i || right!=i))
{ ans++;
break;
}
if(a[left]+a[right]>2*a[i])
left--;
else if(a[left] + a[right]<2*a[i])
right++;
else
left--;
}
}
}
printf("%lld",ans);
return 0;
}