Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int subsequence(int tab[], int n) {
- int max_length = 1; //hold the max_length
- int temp = 1; //hold the temporary max_length
- for (int i = 0; i < n - 1; i++) {
- if(tab[i + 1] >= tab[i]) {
- temp++; //if the next value is larger increase temp
- max_length = max(max_length, temp); //assign largest temp to max_length
- cout << max_length;
- }
- else{
- temp = 1; //otherwise reset temp
- }
- }
- return max_length; //return max_length
- }
- int main() {
- int n;
- cin >> n;
- int* tab = new int[n];
- for(int i = 0; i < n; ++i) {
- cin >> tab[i];
- }
- cout << subsequence(tab, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment