#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=1e9+7;
const int N=2e5+5;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;
int dp[90010];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen(".in", "r", stdin); freopen(".out", "w", stdout);
int n,m,k; cin>>n>>m>>k;
int time[n],cst[m];
for (int &i:time) cin>>i;
for (int &i:cst) cin>>i;
sort(cst,cst+m);
if (m<k) {
cout<<"Impossible";
return 0;
}
int ttl=0;
for (int i=0;i<n;i++) {
ttl+=time[i];
}
dp[0]=1;
map<int,int> mp;
vector<int> ans;
for (int i=0;i<m;i++){
for (int j=90005;j>=cst[i];j--){
dp[j]=max(dp[j],dp[j-cst[i]]);
if (dp[j]>0 && mp[j]==0) {mp[j]=1; ans.push_back(j);}
}
}
int nm=1e18;
if (k==1) {
for (int i=ttl;i<=90005;i++) {
if (nm==0 && mp[i]!=0) {
nm=i; break;
}
}
}
else {
int l=0,r=m-1;
while (l<r) {
if ((cst[l]+cst[r])<ttl) {
l++; continue;
}
nm=min(nm,cst[l]+cst[r]);
r--;
}
}
if (nm==1e18) cout<<"Impossible";
else cout<<nm-ttl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
102 ms |
3060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |