题解
2024-08-17 09:02:33
发布于:广东
4阅读
0回复
0点赞
#include <iostream>
using namespace std;
int main() {
int n, sum;
int a[10000];
int b[10000] = {0};
long long count = 0;
cin >> n >> sum;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
b[a[i] + a[j]]++;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (sum - a[i] - a[j] > 0)
{
count += b[sum - a[i] - a[j]];
}
}
}
cout << count;
return 0;
}
这里空空如也
有帮助,赞一个