Advertisement
Josif_tepe

Untitled

Mar 3rd, 2022
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(false);
  9.     int a;
  10.     cin>>a;
  11.     int l;
  12.     char c;
  13.     int ans=0;
  14.     vector<int>x;
  15.     vector<int>n;
  16.     vector<int>y;
  17.     vector<int>m;
  18.     for(int i=0;i<a;i++)
  19.     {
  20.         cin>>l>>c;
  21.         if(c=='+')
  22.         x.push_back(l);
  23.         if(c=='-')
  24.         n.push_back(l);
  25.     }
  26.     for(int i=0;i<a;i++)
  27.     {
  28.         cin>>l>>c;
  29.         if(c=='+')
  30.         y.push_back(l);
  31.         if(c=='-')
  32.         m.push_back(l);
  33.     }
  34.     sort(x.begin(),x.end());//m +
  35.     sort(n.begin(),n.end());//m -
  36.     sort(y.begin(),y.end());//z +
  37.     sort(m.begin(),m.end());//z -
  38.     for(int i=0;i<x.size();i++)
  39.     {
  40.         int idx=upper_bound(m.begin(),m.end(), x[i])-m.begin();
  41.         if(idx>=0 && idx<m.size())
  42.         {
  43.             ans++;
  44.             m.erase(m.begin() + idx);
  45.         }
  46.     }
  47.     for(int i=0;i<y.size();i++)
  48.     {
  49.         int idx=upper_bound(n.begin(),n.end(), y[i])-n.begin();
  50.         if(idx>=0 && idx<n.size())
  51.         {
  52.             ans++;
  53.             n.erase(n.begin() + idx);
  54.         }
  55.     }
  56.     cout<<ans;
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement