-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotel_Queries.cpp
More file actions
41 lines (41 loc) · 1 KB
/
Copy pathHotel_Queries.cpp
File metadata and controls
41 lines (41 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "bits/stdc++.h"
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,m;
cin>>n>>m;
auto cmp = [](const pair<ll, ll>& a, const pair<ll, ll>& b) {
return a.first < b.first;
};
multiset<pair<ll, ll>, decltype(cmp)> st(cmp);
for(int i=0;i<n;i++){
ll num;
cin>>num;
st.insert(make_pair(num,i));
}
for (int i = 0; i < m; i++) {
ll query;
cin >> query;
auto it=st.lower_bound(make_pair(query, 0));
auto a=it;
ll m=INT32_MAX;
while(a!=st.end()){
m=min(a->second,m);
a++;
}
while(it!=st.end()&&it->second!=m){
it++;
}
if (it == st.end()) {
cout << 0 << " ";
}
else {
cout << it->second + 1 << " ";
pair<ll, ll> updated = make_pair(it->first - query, it->second);
st.erase(it);
st.insert(updated);
}
}
cout<<endl;
}