Submission #134896

#TimeUsernameProblemLanguageResultExecution timeMemory
134896miguelKitchen (BOI19_kitchen)C++14
100 / 100
240 ms118684 KiB
#include<bits/stdc++.h> using namespace std; #define rc(x) return cout<<x<<endl,0 #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define sz size() #define x first #define y second #define pi pair <int, int> #define pii pair <int, pi> #define vi vector <int> #define nmax 301 const ll mod = 998244353; int n, m, k, s; int a[605], b[605], dp[309][100001]; int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cin>>n>>m>>k; if(m<k) return cout<<"Impossible", 0; for(int i=1; i<=n; i++){ cin>>a[i]; s+=a[i]; if(a[i]<k) return cout<<"Impossible", 0; } for(int i=0; i<m; i++) cin>>b[i]; for(int i=0; i<=100000; i++){ for(int j=0; j<=m+1; j++) dp[j][i]=-(1<<30); } dp[0][0]=0; for (int i = 0; i<m; i++) { for (int j = 0; j <= 90000; j++) { if (dp[i][j] == -(1 << 30)) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j + b[i]] = max(dp[i + 1][j + b[i]], dp[i][j] + min(b[i], n)); } } for (int i = s; i <= 90000; i++) { if (dp[m][i] >= n * k) return cout<<i - s, 0; } cout<<"Impossible"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...