This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
#include <bitset>
using namespace std;
typedef long long ll;
typedef long double ld;
#pragma GCC optimize("Ofast")
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 307;
const ll LG = 21;
ll n, m, k;
ll dp[N * N];
ll a[N];
ll b[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
ll suma = 0, sumb = 0;
ll mn = INF;
for (int i = 0; i < n; i++) {
cin >> a[i];
suma += a[i];
mn = min(mn, a[i]);
}
for (int i = 0; i < m; i++) {
cin >> b[i];
sumb += b[i];
}
if (mn < k) {
cout << "impossible\n";
return 0;
}
for (int i = 1; i <= sumb; i++) {
dp[i] = INF;
}
for (int i = 0; i < m; i++) {
for (int j = sumb; j >= b[i]; j--) {
dp[j] = min(dp[j], dp[j - b[i]] + min(b[i], n));
}
}
ll ans = INF;
for (int j = suma; j <= sumb; j++) {
//cout << j << ": " << dp[j] << endl;
if (dp[j] >= n * k && dp[j] != INF) {
ans = min(ans, j - suma);
}
}
if (ans == INF)cout << "impossible\n";
else cout << ans << endl;
}
/// ---- - -------- ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - -------- ------ -------- -- - - -
# | 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... |