Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int a;
- cin>>a;
- int l;
- char c;
- int ans=0;
- vector<int>x;
- vector<int>n;
- vector<int>y;
- vector<int>m;
- for(int i=0;i<a;i++)
- {
- cin>>l>>c;
- if(c=='+')
- x.push_back(l);
- if(c=='-')
- n.push_back(l);
- }
- for(int i=0;i<a;i++)
- {
- cin>>l>>c;
- if(c=='+')
- y.push_back(l);
- if(c=='-')
- m.push_back(l);
- }
- sort(x.begin(),x.end());//m +
- sort(n.begin(),n.end());//m -
- sort(y.begin(),y.end());//z +
- sort(m.begin(),m.end());//z -
- for(int i=0;i<x.size();i++)
- {
- int idx=upper_bound(m.begin(),m.end(), x[i])-m.begin();
- if(idx>=0 && idx<m.size())
- {
- ans++;
- m.erase(m.begin() + idx);
- }
- }
- for(int i=0;i<y.size();i++)
- {
- int idx=upper_bound(n.begin(),n.end(), y[i])-n.begin();
- if(idx>=0 && idx<n.size())
- {
- ans++;
- n.erase(n.begin() + idx);
- }
- }
- cout<<ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement