Submission #423251

# Submission time Handle Problem Language Result Execution time Memory
423251 2021-06-10T20:41:40 Z abdzag Kitchen (BOI19_kitchen) C++17
0 / 100
1000 ms 146652 KB
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;

using namespace std;
int main() {
	cin.sync_with_stdio(false);
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> v(n);
	vector<ll> v2(m);
	rep(i, 0, n)cin >> v[i];
	rep(i, 0, m)cin >> v2[i];
	ll sum = 0;
	rep(i, 0, n)sum += v[i];
	set<ll> s;
	vector<bool> dp(1e7);
	dp[0] = 1;
	rep(i, 0, m) {
		rep(j, 0, 1e7) {
			if (dp[j] && j + v2[i] < 1e7) {
				dp[j + v2[i]] = 1;
			}
		}
	}
	rep(i, 0, 1e7)if (dp[i])s.insert(i);
	if (s.lower_bound(sum) == s.end())cout << "impossible" << endl;
	else cout << *(s.lower_bound(sum)) - sum << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 146652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 146652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 146652 KB Time limit exceeded
2 Halted 0 ms 0 KB -