Cod sursa(job #3281812)

Utilizator Tudor_EnacheEnache Tudor Tudor_Enache Data 3 martie 2025 18:39:38
Problema Oite Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <map>
#include <vector>

std::ifstream in("oite.in");
std::ofstream out("oite.out");
std::vector<int> v;
std::unordered_map<int, int> f;

int main() {
    int n,suma;
    int x, ans = 0;
    in >> n >> suma;
    v.resize(n+1);
    for(int i = 0; i < n; i++) {
        in >> v[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n;j++){
            x = suma - (v[i] + v[j]);
            ans += f[x];
        }
        for(int j = 0; j <= i-1; j++){
            f[v[i] + v[j]]++;
        }
    }
    out << ans << std::endl;
    return 0;

}