ABC-382-C - Kaiten Sushi · znzryb
## 思路讲解
```cpp
struct cmp{
bool operator()(const pll &a,const pll &b) const {
return a.fi>b.fi;
}
};
multiset<pll,cmp> B;
```
给multiset的cmp记得加const,否则有可能CE
```cpp
for(multiset<pll>::iterator it=B.begin();it!=B.end();){
if(it->first<A[i]){
break;
}
multiset<pll>::iterator next_it=next(it);
ans[it->second]=i;
B.erase(it);
it=next_it;
}
```
然后erase()只能传入iterator,不能够传入reverse_iterator
## AC代码
[https://atcoder.jp/contests/abc382/submissions/62419496](https://atcoder.jp/contests/abc382/submissions/62419496)
```cpp
// Problem: C - Kaiten Sushi
// Contest: AtCoder - AtCoder Beginner Contest 382
// URL: https://atcoder.jp/contests/abc382/tasks/abc382_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
const ll MAXN=static_cast<ll>(2e5)+10,INF=static_cast<ll>(5e18)+3;
ll N,M,A[MAXN];
// pll B[MAXN];
struct cmp{
bool operator()(const pll &a,const pll &b) const {
return a.fi>b.fi;
}
};
multiset<pll,cmp> B;
ll ans[MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>N>>M;
FOR(i, 1, N){
cin>>A[i];
}
FOR(i, 1, M){
ll b;
cin>>b;
B.insert({b,i});
}
FOR(i,1,M){
ans[i]=-1;
}
FOR(i,1,N){
for(multiset<pll>::iterator it=B.begin();it!=B.end();){
if(it->first<A[i]){
break;
}
multiset<pll>::iterator next_it=next(it);
ans[it->second]=i;
B.erase(it);
it=next_it;
}
}
FOR(i,1,M){
cout<<ans[i]<<'\n';
}
return 0;
}
/*
AC
https://atcoder.jp/contests/abc382/submissions/62419496
*/
```
## 心路历程(WA,TLE,MLE……)