Advertisement
Cosmin3105

Untitled

Nov 7th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("date.in");
  7. int n, a[100], l[100], mx = 0, poz;
  8.  
  9. int main()
  10. {
  11.  
  12.     f >> n;
  13.     for(int i = 1; i <= n; i++)
  14.         f >> a[i];
  15.     l[n] = 1;
  16.     for(int i = n-1 ; i >= 1; i--){
  17.         int nr = 0;
  18.         for(int k = i+1; k <= n; k++)
  19.             if(a[k] >= a[i] && l[k] > nr)
  20.                 nr = l[k];
  21.         l[i] = nr +1;
  22.  
  23.     }
  24.  
  25.     for(int i = 1; i <= n; i++)
  26.         if(l[i] > mx){
  27.             mx = l[i];
  28.             poz = i;
  29.         }
  30.  
  31.     cout << a[poz] << " ";
  32.     for(int i = poz; i <= n; i++){
  33.         if(a[i] > a[poz] && l[i] == mx - 1){
  34.             cout << a[i] << " ";
  35.             mx--;
  36.         }
  37.     }
  38.  
  39.     return 0;
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /*
  47. 11
  48. 8 3 6 50 10 8 100 30 60 40 80
  49. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement