题解 | #最大序列和#动态规划加滚动数组秒了
最大序列和
https://www.nowcoder.com/practice/df219d60a7af4171a981ef56bd597f7b
#include <bits/stdc++.h> //#include <iostream> //#include <vector> //#include <climits> //#include <algorithm> using namespace std; int main(){ int n; while(cin >> n){ vector<long long> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } long long cur=a[0]; long long maxinum = LONG_MIN; for(int i = 1; i < n; i++){ cur=a[i]+(cur>0?cur:0); maxinum = max(maxinum,cur); } cout << maxinum << endl; } return 0; }