#include <iostream> using namespace std; const int N = 1000010, INF = 0x3f3f3f3f; int a[N], n; int f[N]; //以i结尾的最大子序列 int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int res = -INF; for (int i = 1; i <= n; i ++) { f[i] = max(f[i - 1] + a[i], a[i]); if (res < f[i]) res = f[i]; } if (res < 0) res = 0; cout << res << endl; return 0; }
解题思路:
注意事项:
参考代码:
0.0分
0 人评分