Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a[] = {-2, -3, -5, -1, -2, -1, -6, -3}, endd = 0, startt = 0, s = 0, maks_so_far = INT_MIN, maks_ending_here = 0;
- for(int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
- {
- maks_ending_here += a[i];
- if(maks_so_far < maks_ending_here)
- {
- maks_so_far = maks_ending_here;
- startt = s;
- endd = i;
- }
- if(maks_ending_here < 0)
- {
- maks_ending_here = 0;
- s = i + 1;
- }
- }
- cout << "start: " << startt << endl;
- cout << "end:" << endd << endl;
- cout << "sum:" << maks_so_far << endl;
- }
Add Comment
Please, Sign In to add comment