CSES – Towers

貪心、資料結構

#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
//declare
int n;
vector<int> v;
multiset<int> st;
//
signed main(){
    fastio;
    cin>>n;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        v.push_back(x);
    }
    for(int i=0;i<n;i++){
        auto it = st.upper_bound(v[i]);
        if(it == st.end()) st.insert(v[i]);
        else st.erase(it), st.insert(v[i]);
    }
    cout<<st.size()<<"\n";
    return 0;
}

相關文章

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *