Pagini recente » Istoria paginii runda/preg_oji/clasament | Istoria paginii runda/sdaf/clasament | Cod sursa (job #1009953) | Istoria paginii calibrare-limite-de-timp | Cod sursa (job #2398740)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("nrtri.in");
ofstream fout("nrtri.out");
const int NMax=805;
int N,a[NMax],lg,s;
int main()
{
fin >> N;
for(int i=1;i<=N;i++)
fin >> a[i];
sort(a+1,a+1+N);
for(int i=1;i<N;i++)
for(int j=i+1;j<=N;j++)
{
int poz;
for(lg=1;lg<=N;lg<<=1);
for(poz=1;lg;lg>>=1)
if(poz+lg<=N and a[poz+lg]<=a[i]+a[j])
poz+=lg;
s+=poz-j;
}
fout << s;
return 0;
}