Cod sursa(job #2406189)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 15 aprilie 2019 14:43:17
Problema Oite Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("oite.in");
ofstream g("oite.out");
int n, s, v[2002];
int ap[2002];
unordered_map<int, int>sum2;
int main()
{
    f >> n >> s;
    for(int i = 1; i <= n; ++i)
        f >> v[i];
    for(int i = 2; i <= n; ++i)
        for(int j = i+1; j <= n; ++j)
            sum2[v[i] + v[j]]++;
    long long aa = 0;
    for(int i = 2; i <= n; ++i)
    {
        for(int j = i+1; j <= n; ++j)
            sum2[v[i] + v[j]]--;
        for(int j = i-1; j >= 1; --j)
            aa += sum2[s - v[i] - v[j]];
    }
    g << aa;
    return 0;
}