Pagini recente » Cod sursa (job #3285052) | Viata de dupa olimpiade? (I) - Mediul academic | Cod sursa (job #3285225) | Cod sursa (job #2825636) | Cod sursa (job #2357228)
#include <bits/stdc++.h>
#define NMAX 801
using namespace std;
ifstream f ("nrtri.in");
ofstream g ("nrtri.out");
int n , i , ab , b , c , nr , j;
int a[NMAX];
bool ok(int mij){
if(a[mij] <= ab + b && a[mij] + b >= ab && a[mij] + ab >= b)return true;
return false;
}
int cb(int start){
int st = start , dr = n , mij = 0 , poz = -1;
while(st <= dr){
mij = (dr - st) / 2 + st;
if(ok(mij))poz = mij , dr = mij - 1;
else st = mij + 1;
}
return poz;
}
int main()
{
f>>n;
for(i=1;i<=n;i++)f>>a[i];
sort(a+1,a+n+1);
for(i=1;i<n;i++){
ab = a[i];
for(j=i+1;j<=n;j++)
{
b = a[j];
if(cb(j+1) != -1)
if(n == cb(j+1))nr++;
else nr += n - cb(j+1);
}
}
g<<nr;
return 0;
}