fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const long long MOD=1e9+7;
  4. signed main(){ //int main cũng được nhé, mình quen dùng thôi!
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. long long n;
  8. cin >> n;
  9. vector<int> a(n);
  10. for(int i=0;i<n;i++) cin >> a[i];
  11. int lonnhat=0;
  12. for (int i=0;i<n;i++){ //Phần tử đầu của dãy con
  13. int tong=0;
  14. for (int j=i;j<n;j++){ //Phần tử cuối của dãy con
  15. tong+=a[j];
  16. lonnhat=max(lonnhat,tong); //Vòng lặp cuối cùng không cần thiết lắm!
  17. }
  18. }
  19. cout << lonnhat;
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
Success #stdin #stdout 0s 5304KB
stdin
3
36 67 69
stdout
172