#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;
int ttl=0;
for (int i=0;i<n;i++) {
ttl+=time[i];
}
sort(cst,cst+m);
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=0;
for (int i=ttl;i<=90005;i++) {
if (nm==0 && mp[i]!=0) {
nm=i; break;
}
}
if (nm==0) cout<<"Impossible";
else cout<<nm-ttl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
3028 KB |
Output is correct |
2 |
Correct |
256 ms |
3496 KB |
Output is correct |
3 |
Correct |
367 ms |
4364 KB |
Output is correct |
4 |
Correct |
798 ms |
6632 KB |
Output is correct |
5 |
Correct |
598 ms |
6420 KB |
Output is correct |
6 |
Correct |
146 ms |
2536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
1060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |