Cod sursa(job #2798742)
| Utilizator | Data | 11 noiembrie 2021 19:59:37 | |
|---|---|---|---|
| Problema | Oite | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("oite.in");
ofstream fout("oite.out");
unordered_map<int, int> M;
int a[1026];
int main()
{
int n, s, i, j, x, cnt = 0;
fin >> n >> s;
for (i = 1; i <= n; i++)
fin >> a[i];
sort(a + 1, a + n + 1);
for (i = 1; i < n; i++)
{
for (j = i + 1; j <= n && s - a[i] - a[j] >= 0; j++)
{
x = s - a[i] - a[j];
if (M.count(x) > 0)
cnt += M[x];
}
for (j = 1; j < i; j++)
M[a[i] + a[j]]++;
}
fout << cnt << "\n";
return 0;
}