1 solutions
-
0
C++ :
#include <bits/stdc++.h> #define N 100005 using namespace std; int a[N]; long long dp[N]; int main(){ int n; cin >> n; for (int i =1;i<=n;i++){ cin >> a[i]; } for (int i = 1;i<=n;i++){ if (dp[i-1] >=0){ dp[i] = dp[i-1] + a[i]; } else{ dp[i] = a[i]; } } long long ans = 0; for (int i = 1;i<=n;i++){ ans = max(ans,dp[i]); } cout << ans; return 0; }
- 1
Information
- ID
- 119
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By