#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int m;
cin >> m;
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
int sa = accumulate(a.begin(), a.end(), 0);
const int inf = (int) 1e9;
vector<int> dp(sa + 1, inf);
dp[0] = 0;
multiset<int> st;
for (int i = 0; i < n; i++) {
st.insert(a[i]);
}
for (int i = 0; i < sa; i++) {
for (int j = 0; j < m; j++) {
if ((int) st.size() >= b[j]) {
dp[i + b[j]] = min(dp[i + b[j]], dp[i] + 1);
}
}
auto it = prev(st.end());
int mx = *it;
st.erase(it);
if (mx > 1) {
st.insert(mx - 1);
}
}
if (dp[sa] == inf) {
cout << -1 << '\n';
return 0;
}
vector<int> f;
int p = sa;
while (p > 0) {
int prv = -1;
for (int i = 0; i < m; i++) {
if (p >= b[i] && dp[p] == dp[p - b[i]] + 1) {
prv = p - b[i];
}
}
f.push_back(p - prv);
p = prv;
}
cout << "take\n";
for (int x : f) {
cout << x << '\n';
}
cout << endl;
vector<vector<int>> res;
multiset<pair<int, int>> all;
for (int i = 0; i < n; i++) {
all.emplace(a[i], i);
}
for (int x : f) {
res.push_back({});
vector<int> ids;
for (int i = 0; i < x; i++) {
assert(!all.empty());
auto it = prev(all.end());
res.back().push_back(it->second);
ids.push_back(it->second);
all.erase(it);
}
for (int i : ids) {
a[i] -= 1;
if (a[i] > 0) {
all.emplace(a[i], i);
}
}
}
cout << (int) res.size() << '\n';
for (auto& p : res) {
cout << (int) p.size() << " ";
for (int i = 0; i < (int) p.size(); i++) {
cout << p[i] + 1 << " ";
}
cout << '\n';
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "take" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "take" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "take" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "take" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "take" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "take" found |
2 |
Halted |
0 ms |
0 KB |
- |