Cod sursa(job #2804056)

Utilizator thvulpeTheodor Vulpe thvulpe Data 20 noiembrie 2021 19:39:40
Problema Numarare triunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

int n, a[803], k, s;
int st, dr, mij;
bool f;

int main(){
    fin >> n;
    for(int i = 1; i <= n; i++)
        fin >> a[i];
    for(int i = 1; i < n; i++)
        for(int j = 1; j <= n; j++)
            if(a[i] > a[j])
                swap(a[i], a[j]);
    for(int i = 1; i < n; i++){
        for(int j = i + 1; j <= n; j++){
            s = a[i] + a[j];
            st = 1;
            dr = n;
            while(st < dr){
                mij = (st + dr) / 2;
                if(s >= a[mij])
                    dr = mij - 1;
                else
                    st = mij;
            }
            k += dr;
        }
    }
    fout << dr;
    return 0;
}