听取WA声一片+1(求帮助)
查看原帖
听取WA声一片+1(求帮助)
1570448
puddingEason楼主2025/2/5 21:09

求帮助!!!

学长们麻烦帮忙看一下呗,样例AC但评测全WA……

#include <bits/stdc++.h>
using namespace std;
const int N = 1002;
int n,k,a[N],s[N],ans;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		s[i] = a[i] + s[i - 1];
	}
	sort(a + 1,a + n + 1);
	int j = 1;
	for (int i = 1;i <= n;i++)
	{
		while (a[j] - a[i] <= k && j <= n)
		{
			j++;
		}
		ans = max(ans,s[j - 1] - s[i - 1]);
	}
	cout << ans;
	return 0;
}

用了双指针但错掉了,55555……

2025/2/5 21:09
加载中...