#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17
#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif
#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)
#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)
#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)
auto Start = chrono::high_resolution_clock::now();
inline void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int n, m, k;
int main() {
//fast();
cin >> n >> m >> k;
ll meal_sum = 0;
vector<int> meals(n);
for(int i = 0; i < n; i++) {
cin >> meals[i];
meal_sum += meals[i];
if(meals[i] < k) {
cout << "Impossible";
return 0;
}
}
ll chef_sum = 0;
vector<int> chefs(m);
for(int i = 0; i < m; i++) {
cin >> chefs[i];
chef_sum += chefs[i];
}
vector<int> dp(90010, -1);
dp[0] = 0;
for(int c = 0; c < m; c++) {
int ones = min(chefs[c], n);
vector<int> new_dp(dp.size());
for(int sum = 0; sum < chef_sum + 1; sum++) {
new_dp[sum] = dp[sum];
if(chefs[c] <= sum && dp[sum - chefs[c]] != -1) {
new_dp[sum] = max(new_dp[sum],dp[sum - chefs[c]] + ones);
}
}
dp = new_dp;
}
ll required_ones = n * k;
for(int sum = 0; sum < dp.size(); sum++) {
if(dp[sum] >= required_ones && sum >= meal_sum) {
cout << (sum - meal_sum);
return 0;
}
}
cout << "Impossible";
}
Compilation message
kitchen.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
18 | #pragma GCC optimization ("O3")
|
kitchen.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
19 | #pragma GCC optimization ("unroll-loops")
|
kitchen.cpp: In function 'int main()':
kitchen.cpp:116:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for(int sum = 0; sum < dp.size(); sum++) {
| ~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1012 KB |
Output is correct |
2 |
Correct |
1 ms |
1012 KB |
Output is correct |
3 |
Correct |
1 ms |
1012 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1012 KB |
Output is correct |
2 |
Correct |
1 ms |
1012 KB |
Output is correct |
3 |
Correct |
1 ms |
1012 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
1012 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1012 KB |
Output is correct |
11 |
Correct |
1 ms |
1012 KB |
Output is correct |
12 |
Correct |
1 ms |
1012 KB |
Output is correct |
13 |
Correct |
1 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
980 KB |
Output is correct |
2 |
Correct |
22 ms |
1012 KB |
Output is correct |
3 |
Correct |
22 ms |
980 KB |
Output is correct |
4 |
Correct |
34 ms |
980 KB |
Output is correct |
5 |
Correct |
34 ms |
1012 KB |
Output is correct |
6 |
Correct |
16 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
980 KB |
Output is correct |
2 |
Correct |
2 ms |
1012 KB |
Output is correct |
3 |
Correct |
2 ms |
1012 KB |
Output is correct |
4 |
Correct |
1 ms |
1012 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1012 KB |
Output is correct |
2 |
Correct |
1 ms |
1012 KB |
Output is correct |
3 |
Correct |
1 ms |
1012 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
1012 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1012 KB |
Output is correct |
11 |
Correct |
1 ms |
1012 KB |
Output is correct |
12 |
Correct |
1 ms |
1012 KB |
Output is correct |
13 |
Correct |
1 ms |
1012 KB |
Output is correct |
14 |
Correct |
25 ms |
980 KB |
Output is correct |
15 |
Correct |
22 ms |
1012 KB |
Output is correct |
16 |
Correct |
22 ms |
980 KB |
Output is correct |
17 |
Correct |
34 ms |
980 KB |
Output is correct |
18 |
Correct |
34 ms |
1012 KB |
Output is correct |
19 |
Correct |
16 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
2 ms |
1012 KB |
Output is correct |
22 |
Correct |
2 ms |
1012 KB |
Output is correct |
23 |
Correct |
1 ms |
1012 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
18 ms |
1012 KB |
Output is correct |
26 |
Correct |
30 ms |
1012 KB |
Output is correct |
27 |
Correct |
10 ms |
1012 KB |
Output is correct |
28 |
Correct |
21 ms |
1012 KB |
Output is correct |
29 |
Correct |
23 ms |
1012 KB |
Output is correct |
30 |
Correct |
38 ms |
972 KB |
Output is correct |