Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- int array[n+1];
- for (int i=0;i<n;i++)
- {
- cin>>array[i];
- }
- long long sum=0;
- long long current_sum=0;
- long long max1=-1e18;
- for (int i=0;i<n;i++)
- {
- current_sum=current_sum+array[i];
- if (current_sum>array[i])
- {
- sum=current_sum;
- }
- else
- {
- sum=array[i];
- current_sum=array[i];
- }
- max1=max(max(sum, current_sum), max1);
- }
- cout<<max1<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment