Từ 2025 HEMS 6
Thông tin
include <bits/stdc++.h>
using namespace std;
int main() { int N, K; cin >> N >> K; vector<long long> cnt(1000001, 0); for (int i = 0; i < N; i++) { int x; cin >> x; cnt[x]++;} long long ans = 0; for (int x = 0; x <= K; x++) { int y = K - x; if (y < 0 || y > 1000000) continue; if (x < y) { ans += cnt[x] * cnt[y]; } else if (x == y) { ans += cnt[x] * (cnt[x] - 1) / 2;} } cout << ans; return 0; }