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 <bits/stdc++.h>
using namespace std;
using ll = long long;

ll area;
ll ans;
ll w,h,n;

vector<ll>sizes;
bool possible(ll a){
    return ((a <= w && a <= h && a * a <= area));
}
void solve(ll n){
    for(auto x : sizes) {
        if (possible(x)){
            ans += area / (x * x);
            area -= (area / (x * x)) *  x * x;
        }
    }
    cout << ((ans == 0 || area > 0) ? -1 : ans);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    cin >> w >> h >> n;
    sizes.resize(n);
    area = w * h;
    for(int i = 0;i < n;i++) cin >> sizes[i];
    sort(sizes.rbegin(),sizes.rend());
    solve(n);

    return 0;
}