fork download
  1. /*
  2.  
  3. */
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char const *argv[]) {
  9.  
  10. int vec[] = {1,2,5,-4,5,-6,7,1,-1,-7,1,10,1,-3,4},
  11.  
  12. n = sizeof(vec) / sizeof(vec[0]);
  13.  
  14. int smax, pmax, lmax, i, s, p = 1;
  15.  
  16. i = 0;
  17.  
  18. while(i < n) {
  19.  
  20. while(vec[i] <= 0 && i < n) i++;
  21.  
  22. s = 0;
  23. p = i;
  24.  
  25. while(vec[i] >= 0 && i < n) {
  26. s = s + vec[i];
  27. i++;
  28. }
  29.  
  30. if(s > smax) {
  31. smax = s;
  32. pmax = p;
  33. lmax = i - p;
  34. }
  35. }
  36. cout<<pmax<<"-"<<lmax<<"-"<<smax;
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5416KB
stdin
Standard input is empty
stdout
10-3-12