이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
int dp[90001], dp2[90001];
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
int a[n], b[m];
int x = 0;
bool bad = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
if(a[i] < k)
bad = 1;
}
int sum = 0;
for(int i = 0; i < m; i++) {
cin >> b[i];
sum += b[i];
}
if(bad) {
cout << "Impossible";
return 0;
}
// dp[i] = the maximum number of meals they can prepare in i hours
dp2[0] = 1;
for(int i = 0; i < m; i++) {
for(int j = sum; j >= b[i]; j--) {
dp2[j] |= dp2[j - b[i]];
if(dp2[j - b[i]] && dp[j - b[i]] + min(n, b[i]) > dp[j])
dp[j] = dp[j - b[i]] + min(n, b[i]);
}
}
for(int i = x; i <= sum; i++) {
if(dp[i] >= n * k) {
cout << i - x;
return 0;
}
}
cout << "Impossible";
return 0;
}
# | 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... |