fork(4) download
  1. #include <cmath>
  2. #include <limits.h>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. typedef pair<int,int> ii;
  8. typedef vector<ii> vii;
  9.  
  10. vii client;
  11. vii house;
  12. int indexof(int i,int n,int buyer[])
  13. {
  14. int inx=-1;
  15. int prc=INT_MAX;
  16. for(int j=0;j<n;j++)//client
  17. {
  18. if(buyer[j])
  19. continue;
  20. if(client[j].first<house[i].first && house[i].second<=client[j].second)
  21. {
  22. if(prc>client[j].second)
  23. {
  24.  
  25. inx=j;
  26. prc=client[j].second;
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33. }
  34. return inx;
  35. }
  36. int solve(int n,int m)
  37. {
  38. int sold[m]={0};
  39. int buyer[n]={0};
  40. int c=0;
  41. for(int i=0;i<m;i++)//house
  42. {
  43. int inx=indexof( i,n,buyer);
  44. if(inx>=0)
  45. { c++;
  46. buyer[inx]=1;
  47. }
  48.  
  49.  
  50. }
  51. return c;
  52.  
  53. }
  54. int main() {
  55.  
  56. int n,m;
  57. cin>>n>>m;
  58. client.resize(n);
  59. house.resize(m);
  60. for(auto &x:client)
  61. {
  62. cin>>x.first>>x.second;
  63. }
  64. for(auto &x:house)
  65. {
  66. cin>>x.first>>x.second;
  67. }
  68. sort(house.begin(),house.end());
  69. cout<<solve(n,m);
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 15240KB
stdin
3 3
5 110
9 500
20 400
10 100
2 200
30 300
stdout
2