#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<>());
set < pair<ll, pair<ll, ll>>>dp0;
dp0.emplace(0, make_pair(0, 0));
set<pair<ll, pair<ll, ll>>> dp = dp0;
rep(i, 0, m) {
trav(a, dp0) {
pair<ll, pair<ll, ll>> cur = a;
cur.first += v2[i];
cur.second.first++;
if (cur.second.first > k)cur.second.second += v2[i];
else if(v2[i]<n)cur.second.second-=n-v2[i];
dp.insert(cur);
}
dp0 = dp;
}
ll ans = inf;
trav(a, dp) {
if (a.second.second >= 0&&a.second.first>=k&&a.first>=sum) {
ans = min(ans, a.first);
}
}
if (ans == inf)cout << "Impossible" << endl;
else cout << ans - sum << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
3 ms |
972 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
4048 KB |
Output is correct |
2 |
Correct |
34 ms |
4428 KB |
Output is correct |
3 |
Execution timed out |
1084 ms |
42028 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
654 ms |
58808 KB |
Output is correct |
3 |
Correct |
4 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
3 ms |
972 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
427 ms |
4048 KB |
Output is correct |
15 |
Correct |
34 ms |
4428 KB |
Output is correct |
16 |
Execution timed out |
1084 ms |
42028 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |