forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0455.cpp
35 lines (32 loc) · 878 Bytes
/
0455.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int findContentChildren(vector<int>& g, vector<int>& s)
{
int result = 0;
make_heap(g.begin(), g.end());
sort_heap(g.begin(), g.end());
make_heap(s.begin(), s.end());
sort_heap(s.begin(), s.end());
for (auto g_st = g.begin(), s_st = s.begin(); g_st != g.end()
and s_st != s.end(); ++s_st)
{
result += (*s_st >= *g_st);
g_st += (*s_st >= *g_st);
}
return result;
}
};
int main()
{
vector<int> g = {1,2,3};
vector<int> s = {1,1};
cout << Solution().findContentChildren(g, s) << endl;
return 0;
}