Cod sursa(job #2798799)

Utilizator tomaionutIDorando tomaionut Data 11 noiembrie 2021 21:40:27
Problema Oite Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("oite.in");
ofstream fout("oite.out");
int n, l,a[1030],sol;
unordered_map<int, int> M;
int main()
{
    int i, j,x;
    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 and l - a[i] - a[j] >= 0; j++)
        {
            x = l - a[i] - a[j];
            if (M.find(x) != M.end())
                sol += M[x];
        }
        for (j = 1; j < i; j++)
            M[a[i] + a[j]]++;
    }
    fout << sol;
    return 0;
}