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;
#define int long long
const int inf = 1e18;
int n, m, k, res;
int s1, s2=0, s3=0, s4=0, s5, s6, s7, l;
int dp[100001];
int b[301];
signed main(){
cin >> n >> m >> k;
s7 = inf;
for(int i = 1; i <= n; i++){
cin >> l;
s2 += l;
s7 = min(s7, l);
}
for(int i = 1; i <= m; i++){
cin >> b[i];
s4 += b[i];
}
for(int i = 0; i <= s4; i++)
dp[i] = -inf;
if(s7 < k){
cout << "Imposible";
return 0;
}
dp[0] = 0;
for(int i = 1; i <= m; i++){
for(int j = s4 - b[i]; j >= 0; --j){
dp[j + b[i]] = max(dp[j + b[i]], dp[j] + min(b[i], n));
}
}
s3 = inf;
for(int j = s2; j <= s4; j++){
if(dp[j] >= n * k)
{
cout << j-s2 ;
return 0;
}
}
cout << "Impossible";
}
# | 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... |