Pagini recente » Cod sursa (job #1966793) | Cod sursa (job #305119) | Cod sursa (job #687902) | Cod sursa (job #1227082) | Cod sursa (job #413393)
Cod sursa(job #413393)
#include <fstream>
using namespace std;
#define hg 8192
int N,v[801],poz;
char ch[hg];
FILE *f=fopen("nrtri.in","r");
FILE *g=fopen("nrtri.out","w");
inline void cit (int &x)
{
x = 0;
if (ch[0]=='\0') fread (ch, 1, hg, f);
else while (ch[poz] < '0' || ch[poz] > '9')
if (++poz == hg)
fread (ch, 1, hg, f), poz = 0;
while (ch[poz] >= '0' && ch[poz] <= '9')
{
x = x * 10 + ch[poz] - '0';
if (++poz == hg)
fread (ch, 1, hg, f), poz = 0;
}
}
inline int cb(int i,int j)
{
int st,dr,mij,rez=0;
for (st = j + 1,dr = N;st <= dr; )
{
mij = st + ((dr - st) >> 1);
if (v[i] + v[j] >= v[mij]) rez=mij-j,st=mij + 1;
else dr=mij - 1;
}
return rez;
}
void solve()
{
int i,j,rez=0;
cit(N);
for (i=1;i<=N;i++) cit(v[i]);
sort(v + 1,v + N + 1);
for (i=1;i<=N-1;i++)
for (j=i+1;j<=N;j++)
rez+=cb(i,j);
fprintf(g,"%d",rez);
}
int main()
{
solve();
return 0;
}