#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
/*const int MOD = (int) 1e9 + 7;
inline int lgput(int a, int b) {
int ans = 1;
while(b > 0) {
if(b & 1) ans = (1LL * ans * a) % MOD;
b >>= 1;
a = (1LL * a * a) % MOD;
}
return ans;
}
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
inline void sub(int &x, int y) {
x += MOD - y;
mod(x);
}
inline void mul(int &x, int y) {
x = (1LL * x * y) % MOD;
}*/
/*int fact[], invfact[];
inline void prec(int n) {
fact[0] = 1;
for(int i = 1; i <= n; i++) {
fact[i] = (1LL * fact[i - 1] * i) % MOD;
}
invfact[n] = lgput(fact[n], MOD - 2);
for(int i = n - 1; i >= 0; i--) {
invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
}
}
inline int comb(int n, int k) {
if(n < k) return 0;
return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/
using namespace std;
struct Comp {
int val;
bool operator <(const Comp &other) const {
return val > other.val;
}
};
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
vector <int> a(n);
for(i = 0; i < n; i++) {
cin >> a[i];
}
multiset <Comp> mst;
for(i = 0; i < m; i++) {
int x;
cin >> x;
mst.insert({x});
}
for(i = 0; i < n; i++) {
while(mst.size() && prev(mst.end()) -> val == 0) {
mst.erase(prev(mst.end()));
}
if(mst.size() < k || a[i] < k) {
cout << "Impossible";
return 0;
}
a[i] -= k;
auto it = mst.begin();
vector <int> cur;
for(int j = 0; j < k; j++) {
cur.push_back(it -> val - 1);
it = next(it);
}
mst.erase(mst.begin(), it);
for(int j = 0; j < k; j++) {
mst.insert({cur[j]});
}
while(a[i] > 0) {
a[i]--;
int val = mst.begin() -> val;
if(val == 0) {
cout << "Impossible";
return 0;
}
mst.erase(mst.begin());
mst.insert({val - 1});
}
}
int ans = 0;
for(auto it : mst) {
ans += it.val;
}
cout << ans;
return 0;
}
Compilation message
kitchen.cpp: In function 'int main()':
kitchen.cpp:93:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(mst.size() < k || a[i] < k) {
~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |