-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1092.cpp
More file actions
56 lines (46 loc) · 938 Bytes
/
Copy path1092.cpp
File metadata and controls
56 lines (46 loc) · 938 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
51
52
53
54
55
56
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int N,M;
vector<int> cranes;
multiset<int> boxes;
void input() {
cin >> N;
for (int i=0; i<N; i++) {
int limit;
cin >> limit;
cranes.push_back(limit);
}
cin >> M;
for (int i=0; i<M; i++) {
int weight;
cin >> weight;
boxes.insert(weight);
}
}
void solve() {
sort(cranes.begin(), cranes.end(), greater<int>());
if (*boxes.rbegin() > cranes[0]) {
cout << -1 << '\n';
return;
}
int T = 0;
while (!boxes.empty()) {
for (int crane : cranes) {
auto it = boxes.upper_bound(crane);
if (it == boxes.begin()) break;
boxes.erase(prev(it));
}
T++;
}
cout << T << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
input();
solve();
return 0;
}