#include<iostream> #include<cmath> #include<string> #include<vector> #include<math.h> #include<set> #include<map> #include<algorithm> using namespace std; int Maximum_subsegment_sum(int n,int *a) { int i, sum=0,temp=0; for (i = 0; i < n; i++) { if (temp > 0) { temp += a[i]; } else { temp = a[i]; } if (temp > sum) { sum = temp; } } return sum; } int main() { int i, * a, n; cin >> n; a = new int[n]; for (i = 0; i < n; i++) { cin >> a[i]; } cout << Maximum_subsegment_sum(n, a) << endl; return 0; }
待补……