CSES-Towers problem: help needed!

can anyone help me with this problem in CSES.
Thank you :slight_smile:

#include<bits/stdc++.h>
using namespace std ;
multiset s ;
int n ;
int a[1000000] ;
int main ()
{
cin >> n ;
for (int i=1;i<=n;i++) cin >> a[i] ;
s.insert(a[1]) ;
int res = 1;
for (int i=2;i<=n;i++)
{
auto p = s.upper_bound(a[i]) ;
if (p==s.end()) res++ , s.insert(a[i]) ;
else
{
s.erase(p) ;
s.insert(a[i]) ;
}
}
cout << res;
}
the idea is picking the first element of the array to be the pivot then sorting , if you find the bigger element then push it out another array then find the smaller element to put in the array .