一道题目的通过率只有83.3%,想请大佬们帮忙看看
  • 板块学术版
  • 楼主Acapplella
  • 当前回复20
  • 已保存回复20
  • 发布时间2020/6/13 09:59
  • 上次更新2023/11/7 00:46:07
查看原帖
一道题目的通过率只有83.3%,想请大佬们帮忙看看
325855
Acapplella楼主2020/6/13 09:59

题目链接:数学考试 我的代码通过率只有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;
}
2020/6/13 09:59
加载中...