Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define NMAX 1005
  3.  
  4. using namespace std;
  5.  
  6. ifstream f ("sclm.in");
  7. ofstream g ("sclm.out");
  8.  
  9. int n;
  10. int a[NMAX] , b[NMAX];
  11.  
  12. int main()
  13. {
  14.     int i , j , maxi = 0 , lgmax = 0 , poz = 0;
  15.     f >> n;
  16.     for(i=1;i<=n;i++)
  17.         f >> a[i];
  18.     b[n] = 1;
  19.     for(i=n-1;i>=1;i--)
  20.     {
  21.         maxi = 0;
  22.         for(j=i+1;j<=n;j++)
  23.         if(a[i] <= a[j] && b[j] > maxi)
  24.             maxi = b[j];
  25.         b[i] = maxi + 1;
  26.         if(lgmax <= b[i])
  27.         {
  28.             lgmax = b[i];
  29.             poz = i;
  30.         }
  31.     }
  32.     g << lgmax << '\n';
  33.     for(i=poz;i<=n;i++)
  34.     {
  35.         if(b[i] == lgmax)
  36.         {
  37.             g << i << ' ';
  38.             lgmax--;
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement