# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
747733 | nguyentunglam | Kitchen (BOI19_kitchen) | C++17 | 27 ms | 1364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 310, M = 300 * 300;
vector<int> lst[2];
int f[M + 10], g[M + 10], h[M + 10];
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int n, m, k; cin >> n >> m >> k;
int sum = 0, ans = 1e9;
for(int i = 1; i <= n; i++) {
int x; cin >> x;
if (x < k) return cout << "Impossible", 0;
sum += x;
}
for(int i = 1; i <= m; i++) {
int x; cin >> x;
if (x <= n) lst[0].push_back(x);
else lst[1].push_back(x);
}
f[0] = 1;
for(int &val : lst[0]) for(int j = M; j >= val; j--) if (f[j - val]) f[j] = 1;
h[M + 1] = 1e9;
for(int j = M; j >= 0; j--) {
h[j] = f[j] ? j : h[j + 1];
g[j] = -1e9;
}
g[0] = 0;
for(int &val : lst[1]) for(int j = M; j >= val; j--) g[j] = max(g[j], g[j - val] + 1);
for(int j = 0; j <= M; j++) {
int tmp = max(n * k - g[j] * n, sum - j);
tmp = max(tmp, 0);
if (tmp > M) continue;
int i = h[tmp];
ans = min(ans, j + i - sum);
}
if (ans > 1e8) return cout << "Impossible", 0;
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |