Cod sursa(job #2794420)

Utilizator dnprxDan Pracsiu dnprx Data 4 noiembrie 2021 20:24:54
Problema Oite Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 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;
}