Cod sursa(job #1715310)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 10 iunie 2016 12:04:53
Problema Oite Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

constexpr int MAX_N = 1024;

int A[MAX_N];
int N, L;

int main()
{
    ifstream in("oite.in");
    ofstream out("oite.out");

    ios_base::sync_with_stdio(false);

    in >> N >> L;

    for (int i = 1; i <= N; ++i)
        in >> A[i];

    map<int,int> HashTable;

    long long solutions = 0;

    for (int i = 1; i <= N; ++i)
    {
        for (int j = i + 1; j <= N; ++j)
            if (L - A[i] + A[j] > 0)
                solutions += HashTable[ L - A[i] - A[j] ];

        for (int j = 1; j < i; ++j)
            ++HashTable[ A[i] + A[j] ];
    }

    out << solutions << endl;

    return 0;
}