有大神知道这是怎么回事吗?
查看原帖
有大神知道这是怎么回事吗?
464158
xzabc123楼主2021/10/3 14:43
//P1115
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n,s,mmax= -0x7fffffff,mmin=0;
  int *a;
  //int a[10000000];
  scanf("%d",&n);

  a=new int[n+1]; //asking a space 

  for(int i=1;i<=n;i++){

    scanf("%d",&a[i]);
  }


  //protect max value
  for(int i=1;i<=n;i++){

    s+=a[i];  //walking
    mmax=max(mmax,s-mmin); //protecting the max value
    mmin=min(mmin,s); //protecting the min value
    
    
  }
  printf("%d",mmax);
  return 0;
}

出了什么问题?才40分。 我用的是前缀和求解。

2021/10/3 14:43
加载中...