Cod sursa(job #2610617)

Utilizator anacomoAna-Maria Comorasu anacomo Data 5 mai 2020 10:58:39
Problema Numarare triunghiuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("nrtri.in");
ofstream fout("nrtri.out");

int main()
{
    int n, x;
    vector<int> v;
    fin >> n;
    for(int i = 0; i < n; i++)
        {
            fin >> x;
            v.push_back(x);
        }
    // sortez vectorul
    bool schimb = true;
    while (schimb)
    {
        schimb = false;
        for(int i = 0; i < n-1; i++)
            if(v[i] > v[i+1])
            {
                swap(v[i], v[i+1]);
                schimb = true;
            }
    }
    
    fout << endl;
    int count = 0;
    for(int i = 0; i < n - 2; i++)
        for(int j = i + 1; j < n - 1; j++)
            for(int k = j + 1; k < n && v[i] + v[j] >= v[k]; k++)
                count++;
    fout << count;
    return 0;
}