-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1493.cpp
42 lines (34 loc) · 778 Bytes
/
1493.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
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll arr[20];
ll check(int length, int width, int height) {
if (!length || !width || !height) return 0;
for (int i = 19; i>=0; i--) {
int t = 1<<i;
if (arr[i] && length >= t && width >= t && height >= t) {
arr[i]--;
ll result = 1;
result += check(t, t, height-t);
result += check(length-t, t, height);
result += check(length, width-t, height);
return result;
}
}
return -1e9;
}
void solve(){
ll l,w,h; cin >> l >> w >> h;
int N; cin >> N;
for (int i = 0; i < N; i++) {
ll a,b; cin >> a >> b;
arr[a]+=b;
}
cout << max(-1LL, check(l,w,h));
}
int main (){
cin.tie(0) -> sync_with_stdio(0);
solve();
return 0;
}