fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int arr[n];
  8.  
  9. for (int i = 0; i < n; i++)
  10. cin >> arr[i];
  11.  
  12. int maxLen = 1, start = 0, end = 0;
  13. int batDau[n], ketThuc[n];
  14. int cnt = 0;
  15.  
  16. for (int i = 1; i < n; i++) {
  17. if (arr[i] > arr[i - 1]) {
  18. end = i;
  19. if (end - start + 1 > maxLen) {
  20. maxLen = end - start + 1;
  21. cnt = 0;
  22. batDau[cnt] = start;
  23. ketThuc[cnt] = end;
  24. cnt++;
  25. } else if (end - start + 1 == maxLen) {
  26. batDau[cnt] = start;
  27. ketThuc[cnt] = end;
  28. cnt++;
  29. }
  30. } else {
  31. start = i;
  32. end = i;
  33. }
  34. }
  35.  
  36. cout << maxLen << '\n';
  37. for (int i = 0; i < cnt; i++) {
  38. for (int j = batDau[i]; j <= ketThuc[i]; j++) {
  39. cout << arr[j] << " ";
  40. }
  41. cout << '\n';
  42. }
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5264KB
stdin
Standard input is empty
stdout
6
0 30 31 33 36 38