Cod sursa(job #2846167)

Utilizator dobreraduDobre Radu Fabian dobreradu Data 8 februarie 2022 20:59:48
Problema Oite Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("oite.in");
ofstream fout("oite.out");

int n, L, a[1100], cnt;
unordered_map<int, int>M;

int main()
{
    fin >> n >> L;
    for(int i = 1; i <= n; i++)
        fin >> a[i];
    sort(a+1, a+n+1);
    for(int i = 1; i <= n; i++)
    {

        for(int j = i + 1; j <= n; j++)
        {
            int x = a[i] + a[j];
            if(M.find(L - x) != M.end())
                cnt+=M[L - x];
        }
        for(int j = 1; j < i; j++)
                M[a[i]+a[j]]++;

    }
    fout << cnt;
    return 0;
}