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. for (int j=i;j<n;j++){ //Phần tử cuối của dãy con
  14. int tong=0;
  15. for (int t=i;t<=j;t++){
  16. tong+=a[t]; //Duyệt dãy
  17. }
  18. lonnhat=max(lonnhat,tong);
  19. }
  20. }
  21. cout << lonnhat;
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
Success #stdin #stdout 0s 5304KB
stdin
3
36 67 69
stdout
172