1 int maxsub = sum = 0;
2 for(int i = 1 ; i <= n ; i++){
3 sum += a[i];
4 if(sum > maxsub) maxsub = sum;
5 if(sum < 0) sum = 0;
6 }
7
8 //res = maxsub
求数组某子段的最大和
1 int maxsub = sum = 0;
2 for(int i = 1 ; i <= n ; i++){
3 sum += a[i];
4 if(sum > maxsub) maxsub = sum;
5 if(sum < 0) sum = 0;
6 }
7
8 //res = maxsub
求数组某子段的最大和