Submission #332841

# Submission time Handle Problem Language Result Execution time Memory
332841 2020-12-03T16:49:11 Z sinamhdv Kitchen (BOI19_kitchen) C++11
100 / 100
96 ms 100588 KB
// https://oj.uz/problem/view/BOI19_kitchen
// n3 solution
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'

#define MAXN 320

int asum, bsum;
int dp[MAXN][MAXN * MAXN];
int a[MAXN], b[MAXN];
int n, m, k;

int32_t main(void)
{
	fast_io;
	cin >> n >> m >> k;
	FOR(i, 1, n + 1)
	{
		cin >> a[i];
		if (a[i] < k)
		{
			cout << "Impossible\n";
			return 0;
		}
		asum += a[i];
	}
	FOR(i, 1, m + 1)
	{
		cin >> b[i];
		bsum += b[i];
	}
	fill(dp[0], dp[0] + bsum + 10, -INF);
	dp[0][0] = 0;
	FOR(i, 1, m + 1)
	{
		FOR(j, 0, bsum + 1)
		{
			dp[i][j] = dp[i - 1][j];
			if (j >= b[i])
			{
				dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(b[i], n));
			}
		}
	}
	FOR(i, asum, bsum + 1)
	{
		if (dp[m][i] >= n * k)
		{
			cout << i - asum << endl;
			return 0;
		}
	}
	cout << "Impossible\n";
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 68716 KB Output is correct
2 Correct 54 ms 51308 KB Output is correct
3 Correct 64 ms 57324 KB Output is correct
4 Correct 95 ms 98156 KB Output is correct
5 Correct 93 ms 98284 KB Output is correct
6 Correct 40 ms 41452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 66 ms 68716 KB Output is correct
15 Correct 54 ms 51308 KB Output is correct
16 Correct 64 ms 57324 KB Output is correct
17 Correct 95 ms 98156 KB Output is correct
18 Correct 93 ms 98284 KB Output is correct
19 Correct 40 ms 41452 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 748 KB Output is correct
23 Correct 1 ms 748 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 48 ms 50284 KB Output is correct
26 Correct 61 ms 62060 KB Output is correct
27 Correct 18 ms 19180 KB Output is correct
28 Correct 48 ms 51436 KB Output is correct
29 Correct 72 ms 69996 KB Output is correct
30 Correct 96 ms 100588 KB Output is correct