//Billions of bilious blue blistering barnacles in a thundering typhoon!
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0) , cin.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define str string
#define md ((s + e) / 2)
#define mid ((l + r) / 2)
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
#define C continue
#define R return
#define B break
#define lx node * 2
#define rx node * 2 + 1
#define br(dosomething) {dosomething; break;}
#define co(dosomething) {dosomething ; continue;}
typedef long long ll;
ll q, dp[555555] , Ndp[555555] , a[555555] , b[155555] , m, n, o, p , k;
map < ll , ll > mp;
vll adj[555555];
const ll mod = 1e9 + 7;
str s ;
mt19937 rnd(time(0)) ;
void solve(){
ll op = 0 , pp = 0 ;
cin >> n >> m >> k ;
for(ll i = 1 ; i <= n ; i++){
cin >> a[i] ;
op += a[i] ;
}
for(ll i = 1 ; i <= m ; i++){
cin >> b[i] ;
pp += b[i] ;
}
for(ll i = 1 ; i <= n ; i++){
if(a[i] < k)R void(cout << "Impossible\n") ;
}
for(ll sum = 1 ; sum <= pp ; sum++)dp[sum] = -1e15 ;
for(ll i = 1 ; i <= m ; i++){
for(ll sum = pp ; sum >= 0 ; sum--){
if(b[i] <= sum)dp[sum] = max(dp[sum] , dp[sum - b[i]] + min(b[i] , n)) ;
}
}
for(ll cur = op ; cur <= pp ; cur++){
if(dp[cur] >= n * k)R void(cout << cur - op << "\n") ;
}
cout << "Impossible\n" ;
}
int main(){
fast ;
q = 1 ;
//cin >> q ;
while(q--){
solve() ;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13396 KB |
Output is correct |
2 |
Correct |
7 ms |
13380 KB |
Output is correct |
3 |
Correct |
7 ms |
13380 KB |
Output is correct |
4 |
Correct |
7 ms |
13396 KB |
Output is correct |
5 |
Correct |
7 ms |
13388 KB |
Output is correct |
6 |
Correct |
8 ms |
13268 KB |
Output is correct |
7 |
Correct |
7 ms |
13380 KB |
Output is correct |
8 |
Correct |
8 ms |
13388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13396 KB |
Output is correct |
2 |
Correct |
7 ms |
13380 KB |
Output is correct |
3 |
Correct |
7 ms |
13380 KB |
Output is correct |
4 |
Correct |
7 ms |
13396 KB |
Output is correct |
5 |
Correct |
7 ms |
13388 KB |
Output is correct |
6 |
Correct |
8 ms |
13268 KB |
Output is correct |
7 |
Correct |
7 ms |
13380 KB |
Output is correct |
8 |
Correct |
8 ms |
13388 KB |
Output is correct |
9 |
Correct |
7 ms |
13396 KB |
Output is correct |
10 |
Correct |
8 ms |
13396 KB |
Output is correct |
11 |
Correct |
7 ms |
13380 KB |
Output is correct |
12 |
Correct |
7 ms |
13380 KB |
Output is correct |
13 |
Correct |
9 ms |
13396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
13892 KB |
Output is correct |
2 |
Correct |
17 ms |
13780 KB |
Output is correct |
3 |
Correct |
18 ms |
13768 KB |
Output is correct |
4 |
Correct |
26 ms |
13920 KB |
Output is correct |
5 |
Correct |
25 ms |
14036 KB |
Output is correct |
6 |
Correct |
15 ms |
13756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
13292 KB |
Output is correct |
2 |
Correct |
8 ms |
13376 KB |
Output is correct |
3 |
Correct |
7 ms |
13316 KB |
Output is correct |
4 |
Correct |
8 ms |
13396 KB |
Output is correct |
5 |
Correct |
7 ms |
13268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13396 KB |
Output is correct |
2 |
Correct |
7 ms |
13380 KB |
Output is correct |
3 |
Correct |
7 ms |
13380 KB |
Output is correct |
4 |
Correct |
7 ms |
13396 KB |
Output is correct |
5 |
Correct |
7 ms |
13388 KB |
Output is correct |
6 |
Correct |
8 ms |
13268 KB |
Output is correct |
7 |
Correct |
7 ms |
13380 KB |
Output is correct |
8 |
Correct |
8 ms |
13388 KB |
Output is correct |
9 |
Correct |
7 ms |
13396 KB |
Output is correct |
10 |
Correct |
8 ms |
13396 KB |
Output is correct |
11 |
Correct |
7 ms |
13380 KB |
Output is correct |
12 |
Correct |
7 ms |
13380 KB |
Output is correct |
13 |
Correct |
9 ms |
13396 KB |
Output is correct |
14 |
Correct |
20 ms |
13892 KB |
Output is correct |
15 |
Correct |
17 ms |
13780 KB |
Output is correct |
16 |
Correct |
18 ms |
13768 KB |
Output is correct |
17 |
Correct |
26 ms |
13920 KB |
Output is correct |
18 |
Correct |
25 ms |
14036 KB |
Output is correct |
19 |
Correct |
15 ms |
13756 KB |
Output is correct |
20 |
Correct |
7 ms |
13292 KB |
Output is correct |
21 |
Correct |
8 ms |
13376 KB |
Output is correct |
22 |
Correct |
7 ms |
13316 KB |
Output is correct |
23 |
Correct |
8 ms |
13396 KB |
Output is correct |
24 |
Correct |
7 ms |
13268 KB |
Output is correct |
25 |
Correct |
16 ms |
13872 KB |
Output is correct |
26 |
Correct |
19 ms |
13780 KB |
Output is correct |
27 |
Correct |
11 ms |
13524 KB |
Output is correct |
28 |
Correct |
16 ms |
13780 KB |
Output is correct |
29 |
Correct |
20 ms |
13908 KB |
Output is correct |
30 |
Correct |
26 ms |
14020 KB |
Output is correct |