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<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;
signed main(void){
fastio;
int n, m, k;
cin>>n>>m>>k;
vector<int> a(n), b(m);
for(int i = 0; i < n; i++) cin>>a[i];
for(int i = 0; i < m; i++) cin>>b[i];
for(int i = 0; i < n; i++){
if(a[i] < k){
cout<<"Impossible\n";
return 0;
}
}
vector<int> dp(maxn);
for(int i = 0; i < m; i++){
for(int j = maxn - 1; j >= b[i]; j--){
dp[j] = max(dp[j], dp[j - b[i]] + min(n, b[i]));
}
}
int ttl = accumulate(a.begin(), a.end(), 0);
for(int i = ttl; i < maxn; i++){
if(dp[i] >= n * k){
cout<<i - ttl<<"\n";
return 0;
}
}
cout<<"Impossible\n";
}
# | 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... |