Cod sursa(job #2794405)

Utilizator dnprxDan Pracsiu dnprx Data 4 noiembrie 2021 20:06:07
Problema Oite Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 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, 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++)
                rez += M[L - a[i] - a[j]];
        for(j = 1; j < i; j++)
            M[a[i] + a[j]]++;
    }
    fout << rez << "\n";
    return 0;
}