Untitled
unknown
plain_text
2 years ago
1.3 kB
5
Indexable
#include <iostream> using namespace std; void find_the_longest_decreasing_contiguous_subsequence(int n, int array[100001]){ int current_sequence_start_index = 0, longest_sequence_start_index = 0, longest_sequence_end_index = 0; int max_length = 1; for(int i=1;i<n;i++) { if(array[i] > array[i-1]){ if(i - current_sequence_start_index > max_length){ max_length = i - current_sequence_start_index; longest_sequence_start_index = current_sequence_start_index; longest_sequence_end_index = i-1; } current_sequence_start_index = i; } } if (current_sequence_start_index != n-1) if (n - current_sequence_start_index > max_length) { max_length = n - current_sequence_start_index; longest_sequence_start_index = current_sequence_start_index; longest_sequence_end_index = n-1; } for(int i = longest_sequence_start_index; i <= longest_sequence_end_index; i++) cout << array[i] << " "; } int main() { int n, array[100001]; cin >> n; for(int i=0;i<n;i++){ cin >> array[i]; } find_the_longest_decreasing_contiguous_subsequence(n, array); return 0; }
Editor is loading...