Cod sursa(job #2795817)

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

 using namespace std;



ifstream fin("oite.in");

ofstream fout("oite.out");

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];


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

    {

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

        {

            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;

}