Cod sursa(job #3291657)

Utilizator Luca_georgescuLucageorgescu Luca_georgescu Data 5 aprilie 2025 11:20:14
Problema Oite Scor 100
Compilator cpp-64 Status done
Runda cex_9 Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("oite.in");
ofstream g("oite.out");

unordered_map <int,int> mp;

int n,s,a[100005],nr;

int main()
{
    f >> n >> s;

    for (int i=1; i<=n; i++ )
        f >> a[i];

    for (int i=1; i<=n; i++ )
    {
        for (int j=i+1; j<=n; j++ )
            if ( s>=a[i]+a[j] )
                nr+=mp[s-a[i]-a[j]];

        for (int j=1; j<i; j++ )
            mp[a[i]+a[j]]++;
    }
    g << nr;
    return 0;
}