#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
for (auto a : x) cout << x << ' ';\
cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 2000000;
int a[N], n, k;
struct op {
vector <int> ans;
int v;
};
void solve_same() {
}
void solve_count() {
if (accumulate(a, a + n, 0ll) % k != 0) {
cout << -1 << endl;
return;
}
set <int> p;
vector <op> ans;
for (int i = 0; i < n; ++i) {
if (a[i] && p.size() < k) {
p.insert(i);
}
while (p.size() == k) {
vector <int> tmp;
for (int i : p) tmp.pb(i);
ans.pb({tmp, 1});
for (int i : tmp) {
a[i]--;
if (!a[i]) p.erase(i);
}
}
}
cout << ans.size() << endl;
for (op i : ans) {
cout << i.v << ' ';
for (int j : i.ans) cout << j + 1 << ' ';
cout << endl;
}
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> a[i];
if (*max_element(a, a + n) == *min_element(a, a + n)) {
solve_same();
} else {
solve_count();
}
}
Compilation message
nicegift.cpp: In function 'void solve_count()':
nicegift.cpp:39:30: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
39 | if (a[i] && p.size() < k) {
| ~~~~~~~~~^~~
nicegift.cpp:42:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | while (p.size() == k) {
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Incorrect |
1 ms |
364 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Incorrect |
1 ms |
364 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Incorrect |
1 ms |
364 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
364 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Incorrect |
1 ms |
364 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |