fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3. int t[100007];
  4. int main(){
  5. int x;
  6. cin >> x;
  7. for (int i = 0; i < x; i++){
  8. cin >> t[i];
  9. }
  10. int total = 0;
  11. for (int i = 0; i < x; i++){
  12.  
  13. if(t[i] < 0 && (t[i]+t[i+1]) <= 0){
  14. total = total;
  15. }
  16. //else if(t[i] < 0){
  17. //total = total;
  18. if ((total + t[i]) > (total + t[i] + t[i+1])){
  19. total += t[i];
  20. i++;
  21. }
  22. else if (t[i] > 0){
  23. total += t[i];
  24. }
  25. }
  26. cout << total << endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 4268KB
stdin
Standard input is empty
stdout
0