Cod sursa(job #2795797)

Utilizator mihneazzzMacovei Daniel mihneazzz Data 7 noiembrie 2021 00:06:23
Problema Oite Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>

 using namespace std;



ifstream fin("oite.in");

ofstream fout("oite.out");

unordered_map<int, int> M;

int a[1030];



int main()

{

    int n, L, i, j, x, rez = 0;

    fin >> n >> L;

    for(i = 1; i <= n; i++)

        fin >> a[i];

   /// sort(a + 1, a + n + 1);

    for(i = 1; i < n; i++)

    {

        for(j = i + 1; j <= n && L - a[i] - a[j] >= 0; j++)

        {

            x = L - a[i] - a[j];

            if (M.find(x) != M.end())

                rez += M[x];

        }

        for(j = 1; j < i; j++)

            M[a[i] + a[j]]++;

    }

    fout << rez << "\n";

    return 0;

}