Submission #762169

#TimeUsernameProblemLanguageResultExecution timeMemory
762169anha3k25cvpKitchen (BOI19_kitchen)C++14
9 / 100
1068 ms69948 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define dl double #define st first #define nd second #define II pair <int, int> using namespace std; const int N = 5 + 1e5; const int inf = 7 + 1e9; vector <int> a; vector <vector <int>> f; int main() { #define TASKNAME "" ios_base :: sync_with_stdio (0); cin.tie (0); if ( fopen( TASKNAME".inp", "r" ) ) { freopen (TASKNAME".inp", "r", stdin); freopen (TASKNAME".out", "w", stdout); } int n, m, k; cin >> n >> m >> k; int val = 0; for (int i = 1; i <= n; i ++) { int x; cin >> x; if (x < k) { cout << "Impossible"; return 0; } val += x; } int ma = 0; a.assign(m + 1, 0); for (int i = 1; i <= m; i ++) { cin >> a[i]; ma += a[i]; } sort(a.begin() + 1, a.begin() + m + 1, greater <> ()); f.assign(ma + 1, vector <int> (m + 1, -1)); f[0][0] = 0; int ans = inf; for (int num = 0; num <= m; num ++) for (int sum = ma; sum >= 0; sum --) for (int i = num; i >= 0; i --) if (f[sum][i] >= 0) { if (num < m) f[sum + a[num + 1]][i + 1] = max(f[sum + a[num + 1]][i + 1], f[sum][i] + ((i + 1) % k == 0 ? a[num + 1] : 0)); if (sum >= val && f[sum][i] >= n) ans = min(ans, sum - val); } if (ans < inf) cout << ans; else cout << "Impossible"; return 0; }

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:22:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:23:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...