Pagini recente » Cod sursa (job #1599427) | Cod sursa (job #2959380) | Cod sursa (job #1609493) | Cod sursa (job #3217103) | Cod sursa (job #1908268)
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
vector <int> a;
int x=0;
void read()
{
int n;
ifstream f("nrtri.in");
f >> n;
a.resize(n);
for (int i=0; i<a.size(); i++)
f >> a[i];
f.close();
}
void write()
{
ofstream f("nrtri.out");
f << x;
f.close();
}
void solve()
{
for (int i=0; i<a.size(); i++)
{
for (int j=i+1; j<a.size(); j++)
{
for (int z=j+1; z<a.size() && a[z]<=a[i]+a[j]; z++)
{
x++;
}
}
}
}
main()
{
read();
sort(a.begin(),a.end());
solve();
write();
}