Submission #730809

# Submission time Handle Problem Language Result Execution time Memory
730809 2023-04-26T13:06:30 Z gagik_2007 Kitchen (BOI19_kitchen) C++17
100 / 100
29 ms 980 KB
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
#include <bitset>
using namespace std;

typedef long long ll;
typedef long double ld;

#pragma GCC optimize("Ofast")

#define ff first
#define ss second

ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 307;
const ll LG = 21;
ll n, m, k;
ll dp[N * N];
ll a[N];
ll b[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> k;
	ll suma = 0, sumb = 0;
	ll mn = INF;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		suma += a[i];
		mn = min(mn, a[i]);
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		sumb += b[i];
	}
	if (mn < k) {
		cout << "Impossible\n";
		return 0;
	}
	for (int i = 1; i <= sumb; i++) {
		dp[i] = -INF;
	}
	for (int i = 0; i < m; i++) {
		for (int j = sumb; j >= b[i]; j--) {
			dp[j] = max(dp[j], dp[j - b[i]] + min(b[i], n));
		}
	}
	ll ans = INF;
	for (int j = suma; j <= sumb; j++) {
		//cout << j << ": " << dp[j] << endl;
		if (dp[j] >= n * k) {
			ans = min(ans, j - suma);
		}
	}
	if (ans == INF)cout << "Impossible\n";
	else cout << ans << endl;
}

/// ---- - --------  ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - --------  ------ -------- -- - - -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 840 KB Output is correct
2 Correct 11 ms 724 KB Output is correct
3 Correct 13 ms 596 KB Output is correct
4 Correct 29 ms 956 KB Output is correct
5 Correct 23 ms 980 KB Output is correct
6 Correct 9 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 15 ms 840 KB Output is correct
15 Correct 11 ms 724 KB Output is correct
16 Correct 13 ms 596 KB Output is correct
17 Correct 29 ms 956 KB Output is correct
18 Correct 23 ms 980 KB Output is correct
19 Correct 9 ms 724 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 12 ms 800 KB Output is correct
26 Correct 14 ms 712 KB Output is correct
27 Correct 6 ms 452 KB Output is correct
28 Correct 12 ms 724 KB Output is correct
29 Correct 16 ms 836 KB Output is correct
30 Correct 22 ms 960 KB Output is correct