-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuperMarket.cpp
51 lines (48 loc) · 1.21 KB
/
SuperMarket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<vector<int>> cust;
for(int i=0; i<n; i++){
int q,p;
cin>>q>>p;
cust.push_back({p,q});
}
vector<vector<int>> rice;
for(int i=0; i<m; i++){
int q,p;
cin>>q>>p;
rice.push_back({p,q});
}
sort(cust.begin(), cust.end());
sort(rice.begin(), rice.end());
vector<int> placementlelo(m,0);
int ans = 0;
for(int i=0; i<n; i++){
int quan = -1;
int index = -1;
for(int j=0; j<m; j++){
if(!placementlelo[j]){
if(rice[j][0] > cust[i][0]) break;
if(rice[j][1] > cust[i][1]){
if(quan == -1){
quan = rice[j][1];
index = j;
}
else{
if(quan > rice[j][1]){
index = j;
quan = rice[j][1];
}
}
}
}
}
if(index != -1){
placementlelo[index] = 1;
ans++;
}
}
cout<<ans;
}