题解 | #最大序列和#
最大序列和
https://www.nowcoder.com/practice/df219d60a7af4171a981ef56bd597f7b
#include <iostream> using namespace std; float a[1000010]; float a1[1000010]; int main() { int n; while(cin>>n) { for(int i=0;i<n;++i) { cin>>a[i]; } float maxx = 0; a1[0] = a[0]; for(int i = 0;i<n;++i) { a1[i] = max(a[i],a1[i-1]+a[i]); if(a1[i]>maxx) { maxx = a1[i]; } } cout<<maxx<<endl; } } // 64 位输出请用 printf("%lld")