josiftepe

Untitled

Oct 24th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     int n;
  9.     cin>>n;
  10.     int array[n+1];
  11.     for (int i=0;i<n;i++)
  12.     {
  13.         cin>>array[i];
  14.     }
  15.     long long sum=0;
  16.     long long current_sum=0;
  17.      long long max1=-1e18;
  18.     for (int i=0;i<n;i++)
  19.     {
  20.         current_sum=current_sum+array[i];
  21.         if (current_sum>array[i])
  22.         {
  23.             sum=current_sum;
  24.         }
  25.         else
  26.         {
  27.             sum=array[i];
  28.             current_sum=array[i];
  29.         }
  30.         max1=max(max(sum, current_sum), max1);
  31.     }
  32.  
  33.     cout<<max1<<endl;
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment