pakson

Untitled

Feb 8th, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int subsequence(int tab[], int n) {
  5.  
  6. int max_length = 1; //hold the max_length
  7. int temp = 1; //hold the temporary max_length
  8.  
  9. for (int i = 0; i < n - 1; i++) {
  10. if(tab[i + 1] >= tab[i]) {
  11. temp++; //if the next value is larger increase temp
  12. max_length = max(max_length, temp); //assign largest temp to max_length
  13. cout << max_length;
  14. }
  15. else{
  16. temp = 1; //otherwise reset temp
  17. }
  18. }
  19. return max_length; //return max_length
  20. }
  21. int main() {
  22. int n;
  23. cin >> n;
  24. int* tab = new int[n];
  25. for(int i = 0; i < n; ++i) {
  26. cin >> tab[i];
  27. }
  28. cout << subsequence(tab, n);
  29.  
  30. return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment