이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 9e4+5;
ll dp[sz];
void solve()
{
ll n, m, k, sum = 0, sumb = 0, i, j;
cin >> n >> m >> k;
ll a[n+5], b[m+5];
for(i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
}
for(i = 1; i <= m; i++){
cin >> b[i];
sumb += b[i];
}
sort(a+1, a+n+1);
sort(b+1, b+m+1);
if(m < k || a[1] < k)
{
cout << "Impossible\n";
return;
}
for(i = 1; i <= m; i++)
{
for(j = sz; j >= b[i]; j--)
{
if(j == b[i] || dp[j - b[i]])
dp[j] = max(dp[j], dp[j-b[i]] + min(b[i], n));
}
}
for(i = 1; i <= sz; i++)
{
if(dp[i] >= n * k)
{
cout << i - sum << "\n";
return;
}
}
cout << "Impossible\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
solve();
}
}
# | 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... |