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
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }

    long long total_paintings = 0;
    long long area = static_cast<long long>(h) * w;

    for (int i = n - 1; i >= 0; --i) {
        long long side = d[i];
        long long fit = area / (side * side);

        total_paintings += fit;
        area -= fit * side * side;

        if (area == 0) break;
    }

    if (area == 0) {
        cout << total_paintings << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}