// Jan Zakrzewski #include <bits/stdc++.h> using namespace std; int constexpr N = 40; long long h, w; int n; long long d[N]; long long a[N]; long long sum; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> h >> w; cin >> n; for(int i = 1; i <= n; ++i) cin >> d[i]; for(int i = 1; i <= n; ++i) a[i] = (w / d[i] * d[i]) * (h / d[i] * d[i]); for(int i = 1; i <= n-1; ++i) a[i] -= a[i+1]; ans = 0; sum = 0; for(int i = 1; i <= n; ++i) { ans += a[i] / (d[i] * d[i]); sum += a[i]; } if(sum < h * w) ans = -1; cout << ans << "\n"; return 0; }
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 | // Jan Zakrzewski #include <bits/stdc++.h> using namespace std; int constexpr N = 40; long long h, w; int n; long long d[N]; long long a[N]; long long sum; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> h >> w; cin >> n; for(int i = 1; i <= n; ++i) cin >> d[i]; for(int i = 1; i <= n; ++i) a[i] = (w / d[i] * d[i]) * (h / d[i] * d[i]); for(int i = 1; i <= n-1; ++i) a[i] -= a[i+1]; ans = 0; sum = 0; for(int i = 1; i <= n; ++i) { ans += a[i] / (d[i] * d[i]); sum += a[i]; } if(sum < h * w) ans = -1; cout << ans << "\n"; return 0; } |