Submission #1186324

#TimeUsernameProblemLanguageResultExecution timeMemory
1186324kl0989eKitchen (BOI19_kitchen)C++20
20 / 100
48 ms24716 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pb push_back #define vi vector<int> #define vl vector<ll> #define pi pair<int, int> #define pl pair<ll,ll> #define all(x) (x).begin(),(x).end() int main() { ios::sync_with_stdio(0); cin.tie(0); int n,m,k; cin >> n >> m >> k; vi a(n); vi b(m); for (int i=0; i<n; i++) { cin >> a[i]; } for (int i=0; i<m; i++) { cin >> b[i]; } int s=accumulate(all(b),0); int s2=accumulate(all(a),0); if (*min_element(all(a))<k || m<k || s<s2) { cout << "Impossible\n"; return 0; } bool dp[m+1][s+1]; memset(dp,0,sizeof(dp)); dp[0][0]=1; for (int i=0; i<m; i++) { for (int l=0; l<=s; l++) { if (!dp[i][l]) { continue; } dp[i+1][l]=1; dp[i+1][l+b[i]]=1; } } int ans=1e9; for (int k=s2; k<=s; k++) { if (dp[m][k]) { ans=min(ans,k-s2); } } if (ans==1e9) { cout << "Impossible\n"; } else { cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...