Advertisement
Josif_tepe

Untitled

Nov 25th, 2022
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.     vector <int> elementi;
  11.     for(int i = 0; i < n; i++)
  12.     {
  13.         int x;
  14.         cin >> x;
  15.         elementi.push_back(x);
  16.     }
  17.     vector <int> kuli;
  18.     for(int i = 0; i < n; i++)
  19.     {
  20.         int indeks = lower_bound(kuli.begin(), kuli.end(), elementi[i] + 1) - kuli.begin();
  21.         if(indeks >= 0 and indeks < kuli.size()) {
  22.             kuli[indeks] = elementi[i];
  23.         }
  24.         else {
  25.             kuli.push_back(elementi[i]);
  26.         }
  27.     }
  28.    
  29.     cout << kuli.size() << endl;
  30.     return 0;
  31. }
  32. // 3 8 2 1 5
  33. // kuli: 3 8
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement