Cod sursa(job #2797442)

Utilizator robertanechita1Roberta Nechita robertanechita1 Data 9 noiembrie 2021 21:51:04
Problema Oite Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 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);
///    1 1 1 8 9 10 10 12 12 13
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j < i; j++)
            if(a[i-1] != a[j])
                M[a[i-1]+a[j]]++;
        for(int j = i + 1; j <= n; j++)
            if(a[i] != a[j])
        {
            int x = a[i] + a[j];
            if(M.find(L - x) != M.end())
                cnt+=M[L - x];
        }

    }


    fout << cnt;
    return 0;
}