#include<bits/stdc++.h>
using namespace std;
//Types
using ll = long long;
using db = double;
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
ll t[90007];
void solve(){
ll n, m, k, sum = 0, sum2 = 0;
cin>>n>>m>>k;
bool imp = false;
if(m<k)imp = true;
vector<ll> vec(n), hr(m);
for(ll i = 0; i < n; i++){
cin>>vec[i];
sum+=vec[i];
if(vec[i]<k)imp = true;
}
for(ll i = 0; i < m; i++){
cin>>hr[i];
sum2+=hr[i];
}
if(sum>sum2)imp = true;
sort(all(hr));
// 5 5 5
//
// 14 1
if(m<=2){
for(ll i = 0; i < m; i++){
if(hr[i]<n)imp = true;
}
ll ans = BIGINF;
if(imp)cout<<"Impossible";
// cout<<sum2 - sum;
else if(k==1){
if(m==1){
if(sum2 > sum)ans = min(ans, sum2-sum);
}
if(m==2){
if(hr[0]>sum)ans = min(ans, hr[0]-sum);
if(hr[1]>sum)ans = min(ans, hr[1]-sum);
}
if(ans==BIGINF)cout<<sum2-sum;
else cout<<ans;
}
else cout<<sum2-sum;
}
else{
t[0] = 1;
for(ll i = 0; i < m; i++){
for(ll j = 90007; j>= hr[i]; j--){
t[j] = (t[j] or t[j-hr[i]]);
}
}
ll ans = -1;
for(ll i = sum; i <= 90007; i++){
if(t[i]!=0){
ans = i;
break;
}
}
if(ans==-1 or imp)cout<<"Impossible";
else cout<<ans - sum;
}
}
int main(){
Speeed
ll t=1;
// cin>>t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
980 KB |
Output is correct |
2 |
Correct |
28 ms |
980 KB |
Output is correct |
3 |
Correct |
34 ms |
1012 KB |
Output is correct |
4 |
Correct |
30 ms |
1012 KB |
Output is correct |
5 |
Correct |
34 ms |
980 KB |
Output is correct |
6 |
Correct |
26 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |