题解 | #最大序列和#
#include <iostream> using namespace std; const int N = 1000010; int n; int a[N], f[N]; int main() { while(cin >> n) { for(int i = 0; i < n; i++) scanf("%d", &a[i]), f[i] = a[i]; for(int i = 1; i < n; i++) { f[i] = max(f[i], f[i-1] + a[i]); } int res = f[0]; for(int i = 0 ; i < n; i++) if(f[i] > res) res = f[i]; cout << res << endl; } }