1 条题解

  • 0
    @ 2023-6-21 19:29:54

    C++ :

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #define maxn 10005
    #define INF 2000000005
    using namespace std;
    int line[maxn];
    int pre[maxn];
    int ans[maxn];
    int n, m;
    int main(){
        scanf("%d%d", &n, &m);
        int x;
        for (int i = 1; i <= n; i++){
            scanf("%d", &line[i]);
            pre[i] = pre[i - 1] + line[i];
        }
        ans[n + 1] = -INF;
        for (int i = n; i >= 1; i--){
            ans[i] = ans[i + 1];
            for (int j = 1; j <= n - i + 1; j++){
                ans[i] = max(ans[i], pre[j + i - 1] - pre[j - 1]);
            }
        }
        for (int i = 0; i < m; i++){
            scanf("%d", &x);
            printf("%d\n", ans[x]);
        }
        return 0;
    }
    
    • 1

    #514. 「邢台编程 β Round #2」模拟只会猜题意

    信息

    ID
    987
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者