This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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 |
---|
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... |