Pagini recente » Cod sursa (job #1220878) | Cod sursa (job #1014105) | Cod sursa (job #2650984) | Cod sursa (job #1530377) | Cod sursa (job #2910873)
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
//ifstream f("in.in");
//ofstream g("out.out");
ifstream f("nrtri.in");
ofstream g("nrtri.out");
int v[805],n,sol=0,st,dr,x,mij;
int main(){
f>>n;
for(int i=1;i<=n;i++){
f>>v[i];
}
sort(v+1,v+n+1);
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
st=j+1,dr=n,x=-1;
while(st<=dr){
mij = (st+dr)/2;
if(v[mij]>v[i]+v[j]){
x = mij;
dr = mij-1;
}else{
st = mij+1;
}
}
if(x!=-1)
sol+=(x-1-j);
}
}
g<<sol;
f.close();
g.close();
return 0;
}