Pagini recente » Cod sursa (job #956480) | Cod sursa (job #709010) | Cod sursa (job #1890803) | Cod sursa (job #2788551) | Cod sursa (job #1654796)
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <map>
#define pb push_back
#define mp make_pair
#define INF numeric_limits<int>::max()
#define bit(x) (-x)&x
#define int64 long long
using namespace std;
ifstream in("nrtri.in");
ofstream out("nrtri.out");
int v[808],n;
int binsearch(int x,int left,int right)
{
while(left<=right)
{
int mid=(left+right)/2;
if(v[mid]<=x)left=mid+1;
else right=mid-1;
}
return (left+right)/2;
}
int main()
{
in>>n;
for(int i=1;i<=n;i++)
in>>v[i];
int sol=0;sort(v+1,v+n+1);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
sol+=binsearch(v[i]+v[j],j+1,n)-j;
out<<sol<<'\n';
return 0;
}