Pagini recente » Istoria paginii blog/viata-dupa-olimpiade-1 | Istoria paginii blog/viata-dupa-olimpiade-1 | Cod sursa (job #2912151) | Atasamentele paginii Administrare | Cod sursa (job #2357079)
#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)nr++;
}
}
g<<nr;
return 0;
}