300,6,14021,d,XC230720

Hi, for some reason my code doesn’t work, its not allowing to erase iterator. Can I please have some help?
also why cannot I do long long(itr-price.begin());, the compiler throws an error.

#include <iostream>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;
int main() {
    long long n,m;
    cin>>n>>m;
    multiset<long long> price;
    long long customer[m];
    for(long long i=0;i<n;i++)
    {
        long long temp;
        cin>>temp;
        price.insert(temp);
    }
    for(long long i=0;i<m;i++){
        cin>>customer[i];
    }
    for(int i=0;i<m;i++){
        multiset<long long>::iterator itr = upper_bound(price.begin(),price.end(),customer[i]);
        itr--;
        long long maxprice=*itr;
        cout<<maxprice<<"\n";
        multiset<ll>::iterator x=price.find(maxprice);
        price.erase(x);
    }
}
5 个赞

Can you speak Chinese?

2 个赞

Maybe you can use Markdown like:
image

2 个赞

This code can run!

1 个赞

where you insert “long long(itr-price.begin())”?
and what’s the question?
I think maybe you used a define “ll” so you can’t use “long long” so far, if I’m wrong, please tell me

3 个赞

10 个帖子被合并到现有话题中:垃圾站/废贴集中