Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  playground_abc
  4. //
  5. //  Created by Maxim Tsygankov on 10/18/17.
  6. //  Copyright © 2017 Maxim Tsygankov. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <set>
  13. #include <fstream>
  14. #include <string>
  15. #include <map>
  16.  
  17. using namespace std;
  18.  
  19. int main(int argc, const char * argv[]) {
  20.     int n;
  21.     cin >> n;
  22.    
  23.     int maxSum;
  24.     cin >> maxSum;
  25.     int curSum = maxSum;
  26.     for (int i = 1; i < n; i++) {
  27.         int num;
  28.         cin >> num;
  29.         if (curSum + num < num) {
  30.             curSum = num;
  31.         }else{
  32.             curSum += num;
  33.         }
  34.        
  35.         maxSum = max(maxSum, curSum);
  36.        
  37.     }
  38.    
  39.     cout << maxSum << endl;
  40.    
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement