Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int getMaxSum(int *a, int n)
- {
- int bestSum = a[0];
- int best[100];
- for (int i = 0; i < n; i++)
- {
- best[i] = max(a[i], best[i - 1] + a[i]);
- bestSum = max(best[i], bestSum);
- }
- return bestSum;
- }
- int main()
- {
- int a[]= {-1, 2, 3, -4, -2, 2, 1, -3, -2, -3, -4, 9, -2, 1, 7, 8, -19, -7, 2, 4, 3};
- cout << getMaxSum(a, 21);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement