8-1 最大连续和
作者:互联网
#include <bits/stdc++.h> using namespace std; const int maxn = 10010; int a[maxn], s[maxn]; int main() { int n; int mins = 999999, ans = -999999; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; s[i] = s[i - 1] + a[i]; mins = min(mins, s[i]); ans = max(ans, s[i] - mins); } cout << ans; }
Make your program run faster depending on its math feature.
标签:最大,int,999999,maxn,连续,ans,mins,cout 来源: https://www.cnblogs.com/vv123/p/15113712.html