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
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long
int calculate(ll &area, ll &darea) {
    int res = 0;
    while(area / darea <= 1){
        area += darea;
        res++;
    }
    return res;
}

int main() {
    int h, w, n;
    std::cin >> h >> w >> n;

    std::vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> d[i];
    }


    std::sort(d.rbegin(), d.rend());

    ll area = static_cast<ll>(h) * w;
    ll result = 0;

    for (int i = 0; i < n; i++) {
        ll darea = static_cast<ll>(d[i]) * d[i];
        int count = area / darea;
        area -= darea * count;
        if (i < n - 1) {
            ll darea1 = static_cast<ll>(d[i + 1]) * d[i + 1];
            result += count - calculate(area, darea1);
        }
        else {
            result += count;
        }
    }

    if (area == 0) {
        std::cout << result << std::endl;
    }
    else {
        std::cout << "-1" << std::endl;
    }

    return 0;
}