Cod sursa(job #3331484)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 28 decembrie 2025 16:56:31
Problema Oite Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>

#define ll long long

using namespace std;

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

const int NMAX = 1024;

int n, s;
ll answer;
int a[NMAX + 1];
unordered_map<ll, int> mp;

int main()
{
    fin >> n >> s;
    for(int i = 1; i <= n; i++) {
        fin >> a[i];
    }

    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            int need = s - a[i] - a[j];
            if(mp.count(need)) {
                answer += mp[need];
            }
        }
        for(int j = 1; j <= i - 1; j++) {
            mp[a[i] + a[j]]++;
        }
    }
    fout << answer << '\n';
    return 0;
}