Submission #648720

#TimeUsernameProblemLanguageResultExecution timeMemory
648720LoboKitchen (BOI19_kitchen)C++17
100 / 100
118 ms199448 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 303; int n, m, k, a[maxn], b[maxn], dp[maxn][maxn*maxn]; void solve() { cin >> n >> m >> k; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= m; i++) cin >> b[i]; int sma = 0; for(int i = 1; i <= n; i++) { sma+= a[i]; if(a[i] < k) { cout << "Impossible" << endl; return; } } int smb = 0; for(int i = 1; i <= m; i++) smb+= b[i]; dp[0][0] = 0; for(int i = 1; i <= smb; i++) dp[0][i] = -inf; for(int i = 1; i <= m; i++) { for(int j = 0; j <= smb; j++) { dp[i][j] = dp[i-1][j]; if(j-b[i] >= 0) dp[i][j] = max(dp[i][j],dp[i-1][j-b[i]]+min(n,b[i])); } } int ans = inf; for(int i = sma; i <= smb; i++) { if(dp[m][i] >= n*k) { cout << i-sma << endl; return; } } cout << "Impossible" << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { solve(); } }

Compilation message (stderr)

kitchen.cpp: In function 'void solve()':
kitchen.cpp:45:9: warning: unused variable 'ans' [-Wunused-variable]
   45 |     int ans = inf;
      |         ^~~
#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...