답안 #423694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423694 2021-06-11T11:30:20 Z abdzag Kitchen (BOI19_kitchen) C++17
100 / 100
49 ms 1120 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];
		if (v[i] < k) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	rep(i, 0, m)cin >> v2[i];
	ll sum = 0;
	rep(i, 0, n)sum += v[i];
	sort(all(v2), greater<>());
	vector <ll>dp0(1e5,-inf);
	dp0[0]= 0;;
	ll ans = inf;
	ll sumv2 = 0;
	ll sumk = 0;
	rep(i, 0, m) {
		rrep(j, sumv2,-1) {
			dp0[j + v2[i]] = max(dp0[j + v2[i]], dp0[j] + min(n, v2[i]));
		}
		sumv2 += v2[i];
		sumk++;
	}
	rep(i, sum, sumv2+1) {
		if (dp0[i] >= n * k) {
			ans = i;
			break;
		}
	}
	if (ans == inf)cout << "Impossible" << endl;
	else cout << ans - sum << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1100 KB Output is correct
2 Correct 25 ms 1120 KB Output is correct
3 Correct 37 ms 1100 KB Output is correct
4 Correct 49 ms 1100 KB Output is correct
5 Correct 48 ms 1100 KB Output is correct
6 Correct 22 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 33 ms 1100 KB Output is correct
15 Correct 25 ms 1120 KB Output is correct
16 Correct 37 ms 1100 KB Output is correct
17 Correct 49 ms 1100 KB Output is correct
18 Correct 48 ms 1100 KB Output is correct
19 Correct 22 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 25 ms 1116 KB Output is correct
26 Correct 34 ms 1104 KB Output is correct
27 Correct 12 ms 1100 KB Output is correct
28 Correct 20 ms 1100 KB Output is correct
29 Correct 35 ms 1116 KB Output is correct
30 Correct 49 ms 1100 KB Output is correct