静かで孤独な日記

のんびりたまに

ARC092-C 2D Plane 2N Points

using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
vector<pair<int,int> > aka,ao;
bool past[101];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n;
  for(int i=0;i<n;i++){
    int a,b;cin>>a>>b;
    aka.push_back({a,b});
  }
  for(int i=0;i<n;i++){
    int a,b;cin>>a>>b;
    ao.push_back({a,b});
  }
  sort(ao.begin(),ao.end());
  int ans=0;
  for(int i=0;i<n;i++){
    int maxy=-1;
    int res=-1;
    for(int j=0;j<n;j++){
      if(past[j])continue;
      if(aka[j].fi<ao[i].fi && aka[j].se<ao[i].se){
        if(maxy<aka[j].se){
          res=j;
          maxy=aka[j].se;
        }
      }
    }
    if(res!=-1){
      past[res]=1;
      ans++;
    }
  }
  print(ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}
  • 赤の点は左下にあるほど貴重なので、青の点と友達にするのは取れる赤の点のうち最も下にあるもの。
  • これを最初に青のx座標でソートして行えば大丈夫。
  • x座標でソートしたら、もう赤のx座標のことは考えなくていいよね。