Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- using namespace std;
- int main()
- {
- int n,m;
- cin >>n>>m;
- set <int>good;
- multiset<int>real1;
- set <int>real;
- int x;
- for (int i=0 ;i<n ;i++)
- {
- cin >>x;
- good.insert(x);
- }
- for (int i=0 ;i<m;i++)
- {
- cin >>x;
- real.insert(x);
- real1.insert(x);
- }
- if (m<n)
- {
- set <int>::iterator k,c;
- int res=0;
- for (k=good.begin() ;k!=good.end() ;k++)
- {
- c=real.find(*k);
- if (c!=real.end())
- {
- if (*c==*k)
- {
- res--;
- }
- }
- else
- {
- c=real1.upper_bound(*k);
- if (c!=real1.end())
- {
- res--;
- good.erase(*k);
- real1.erase(c);
- }
- }
- }
- res+=good.size();
- cout <<res<<endl;
- }
- else
- {
- int res=0;
- int g=good.size();
- set <int>::iterator k,c;
- for (k=good.begin() ;k!=good.end() ;k++)
- {
- c=real.find(*k);
- if (c!=real.end())
- {
- res--;
- good.erase(*k);
- real1.erase(real1.find(*k));
- }
- else
- {
- c=real1.upper_bound(*k);
- if (c!=real1.end())
- {
- res--;
- good.erase(*k);
- real1.erase(c);
- }
- }
- }
- res+=g;
- cout <<res<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment