Advertisement
yuawn

algo2017_week5_Maximum_Sum_Subarray

Oct 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fo(n) for(int i=0;i<n;i++)
  4.  
  5. int main(){
  6.     int t;
  7.     cin >> t;
  8.    
  9.     while( t-- ){
  10.         int n , tmp , sum = -1 , ans = -2147483647;
  11.         cin >> n;
  12.         fo( n ){
  13.             cin >> tmp;
  14.             if( sum > 0 ) sum += tmp;
  15.             else sum = tmp;
  16.             ans = sum > ans ? sum : ans;
  17.         }  
  18.         cout << ans << endl;
  19.     }
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement