-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
55 lines (54 loc) · 1.5 KB
/
B.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
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int main()
{
fastio;
long long n,i,j,k,sum=0,high,low,mid,p;
static long long ara[103];
cin>>n;
for(i=0;i<n;i++)
cin>>ara[i];
sort(ara,ara+n);
for(i=0;i<n-2;i++)
{
for(j=i+1;j<n-1;j++)
{
if(ara[i]==ara[j])
continue;
else
{
for(k=j+1;k<n;k++)
{
if(ara[j]==ara[k])
continue;
else
{
low=k;
high=n-1;
p=0;
while(low<=high)
{
mid=(low+high)/2;
if(ara[mid]>=ara[i]+ara[j] && ara[mid-1]<ara[i]+ara[j])
{
sum=sum+mid-k;
p=1;
break;
}
else if(ara[mid]<ara[i]+ara[j])
low=mid+1;
else if(ara[mid]>=ara[i]+ara[j])
high=mid-1;
}
if(p==0)
sum=sum+n-k;
break;
}
}
}
}
}
cout<<sum<<endl;
return 0;
}