Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- int n, a[100], l[100], mx = 0, poz;
- int main()
- {
- f >> n;
- for(int i = 1; i <= n; i++)
- f >> a[i];
- l[n] = 1;
- for(int i = n-1 ; i >= 1; i--){
- int nr = 0;
- for(int k = i+1; k <= n; k++)
- if(a[k] >= a[i] && l[k] > nr)
- nr = l[k];
- l[i] = nr +1;
- }
- for(int i = 1; i <= n; i++)
- if(l[i] > mx){
- mx = l[i];
- poz = i;
- }
- cout << a[poz] << " ";
- for(int i = poz; i <= n; i++){
- if(a[i] > a[poz] && l[i] == mx - 1){
- cout << a[i] << " ";
- mx--;
- }
- }
- return 0;
- }
- /*
- 11
- 8 3 6 50 10 8 100 30 60 40 80
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement