-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignCookies.cpp
More file actions
50 lines (40 loc) · 753 Bytes
/
Copy pathAssignCookies.cpp
File metadata and controls
50 lines (40 loc) · 753 Bytes
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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(), g.end());
sort(s.begin(), s.end());
int i = 0, j = 0;
while(i < g.size() && j < s.size()) {
if(s[j] < g[i]) j++;
else {
i++;
j++;
}
}
return i;
}
};
int main() {
int n;
cin>>n;
vector<int> g;
for(int i = 0; i < n; i++) {
int num;
cin>>num;
g.push_back(num);
}
cin>>n;
vector<int> s;
for(int i = 0; i < n; i++) {
int num;
cin>>num;
s.push_back(num);
}
Solution *solution = new Solution();
cout<<solution->findContentChildren(g, s);
return 0;
}