Submission #1135028

#TimeUsernameProblemLanguageResultExecution timeMemory
1135028lucaskojimaKitchen (BOI19_kitchen)C++17
20 / 100
44 ms328 KiB
// subtask 3 #include "bits/stdc++.h" #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() using namespace std; using ll = long long; using pii = pair<int, int>; const char nl = '\n'; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, m, k; cin >> n >> m >> k; // k = 1 vector<int> a(n); for (auto &x : a) cin >> x; vector<int> b(m); for (auto &x : b) cin >> x; int sumA = accumulate(all(a), 0); int sumB = accumulate(all(b), 0); vector<bool> dp(sumB + 1); dp[0] = 1; for (int i = 0; i < m; i++) for (int val = sumB; val >= 1; val--) { if (val - b[i] < 0) continue; dp[val] = (dp[val] || dp[val - b[i]]); } for (int val = sumA; val <= sumB; val++) if (dp[val]) { cout << val - sumA << nl; return 0; } cout << "Impossible" << nl; 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...