Cod sursa(job #3350387)

Utilizator iustinG1314Gorgan Iustin iustinG1314 Data 7 aprilie 2026 14:46:21
Problema Numarare triunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <algorithm>
using namespace std;

int n, v[805];
long long ans;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> v[i];

    sort(v + 1, v + n + 1);

    for(int k = 3; k <= n; k++)
    {
        int i = 1, j = k - 1;
        while(i < j)
        {
            if(v[i] + v[j] >= v[k])
            {
                ans += (j - i);
                j--;
            }
            else
                i++;
        }
    }

    cout << ans;

    return 0;
}