Cod sursa(job #3300556)

Utilizator EricDimiCismaru Eric-Dimitrie EricDimi Data 16 iunie 2025 23:53:08
Problema Numarare triunghiuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MAX_DIM = 800;

int a[MAX_DIM + 1], n;
int64_t cnt;

int main() {
   fin >> n;
   for (int i = 1; i <= n; i++)
      fin >> a[i];
   
   sort(a + 1, a + 1 + n);
   cnt = 0;
   
   for (int i = 1; i < n - 1; i++)
      for (int j = i + 1; j < n; j++)
         for (int k = j + 1; k <= n; k++)
            if (a[k] <= a[i] + a[j])
               cnt++;
      
   fout << cnt << "\n";
   
   fin.close();
   fout.close();
   return 0;
}