CSES – Concert Tickets

資料結構、二分搜

#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,m;
vector<int> t;
multiset<int> st;
//
signed main(){
    fastio;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        st.insert(x);
    }
    for(int i=0;i<m;i++){
        int x; cin>>x;
        t.push_back(x);
    }
    for(int i:t){
        auto it = st.upper_bound(i);
        if(it == st.begin()){
            cout<<-1<<"\n";
        }
        else{
            cout<<*prev(it)<<"\n";
            st.erase(prev(it));
        }
    }
    return 0;
}

相關文章

發佈留言

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