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
#include <bits/stdc++.h>

using namespace std;

int minObrazy(int h, int w, vector<int>& obrazy) {
    int n = obrazy.size();
    vector<vector<int>> dp(n + 1, vector<int>(w + 1, -1));

    for (int i = 0; i <= n; ++i)
        dp[i][0] = 0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= w; ++j) {
            if (obrazy[i - 1] <= j && dp[i][j - obrazy[i - 1]] != -1) {
                dp[i][j] = max(dp[i - 1][j], 1 + dp[i][j - obrazy[i - 1]]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    return (dp[n][w] == -1) ? 0 : (h / obrazy[n - 1]) * dp[n][w];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;

    vector<int> obrazy(n);
    for (int i = 0; i < n; ++i)
        cin >> obrazy[i];

    sort(obrazy.begin(), obrazy.end());

    int wyn = minObrazy(h, w, obrazy);
    cout << wyn-1 << endl;

    return 0;
}