This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
#define int long long
using namespace std;
const int sz = 3e2 + 6;
int a[sz], b[sz];
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
int sm = 0;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
sm += a[i];
}
for (int i = 1; i <= m; i ++) {
cin >> b[i];
}
if (k > m) {
cout << "Impossible";
return 0;
}
if (1 == m) {
int r = (sm / b[1]) * b[1];
if (r < sm) r += b[1];
cout << r - sm;
} else if (2 == m) {
int r = INT_MAX;
int d = 2 == k;
for (int i = d; i <= 10000; i ++) {
for (int j = d; j <= 10000; j ++) {
if (i * b[1] + j * b[2] >= sm) {
r = min(r, i * b[1] + j * b[2] - sm);
}
}
}
cout << r;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |