fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 100000;
  5.  
  6. int main() {
  7. int n, v[MAX_LENGTH + 1];
  8. cin >> n;
  9. int nuleCount = 0, firstPos = 1, lastPos = 0;
  10. for (int i = 1; i <= n; ++i) {
  11. cin >> v[i];
  12. }
  13.  
  14. int flag = 1;
  15. int counter = 0;
  16. for (int i = 1; i <= n; ++i) {
  17. if (v[i] * v[i + 1] != 0 && flag == 1) {
  18. if (counter >= nuleCount) {
  19. nuleCount = counter;
  20. lastPos = i;
  21. firstPos = i - counter ;
  22. counter = 0;
  23. ///flag = 1;
  24. }
  25. flag = 0;
  26.  
  27. } else if (v[i] * v[i + 1] == 0) {
  28. ++counter;
  29. flag = 1;
  30. }
  31.  
  32. }
  33. cout << firstPos << " " << lastPos <<" " << counter<<" \n";
  34. for (int i = firstPos; i <= lastPos; ++i) {
  35. //cout << v[i] <<" ";
  36. }
  37. //cout << firstPos << " " << lastPos;
  38. return 0;
  39. }
  40. /*
  41.  
  42. 1 2 3 4 0 1 0 5 6
  43. */
  44.  
Success #stdin #stdout 0.01s 5312KB
stdin
15
1 0 1 0 2 1 2 2 2 1 0 1 0 1 0 
stdout
1 5 6