题目链接:数学考试 我的代码通过率只有83.3%,但是我不知道我错在哪里,想请大佬们帮我看看。感谢! 错误的代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 200010;
//#define DEBUG
//#define WAR
#define BEGAIN
typedef long long ll;
ll s[maxn],q[maxn];
int a[maxn];
int main()
{
int t;
cin >> t;
while (t--)
{
int n, k;
//scanf("%d%d",&n,&k);
cin>>n>>k;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
#ifdef DEBUG
for (int i = 1;i <= n;i++)
cout << s[i] << " ";
cout << endl;
#endif
for (int i = 1;k + i - 1 <= n;i++)
q[i] = s[k + i - 1] - s[i - 1];
#ifdef WAR
for (int i = 1;k + i - 1 <= n;i++)
cout << q[i] << " ";
cout << endl;
#endif
#ifdef BEGAIN
ll sum = -0x3f3f3f3f,ans=-0x3f3f3f3f;
for (int i = k+1;i<=n-k+1 ;i++)
{
sum = max(sum, q[i-k]);
ans = max(ans, sum + q[i]);
}
cout << ans << endl;
#endif
}
return 0;
}