#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
using namespace std;
const int N = 2 * 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int TN = 1;
int n, k;
pair<int, int> a[N];
vector<vector<int>> ans;
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].fi;
a[i].se = i;
}
while (true) {
sort(a + 1, a + 1 +n, [](pair<int, int> x, pair<int, int> y) {
if (x.fi > y.fi) {
return true;
}
else if (x.fi < y.fi) {
return false;
}
else {
if (x.se < y.se) {
return true;
}
else {
return false;
}
}
});
bool can = true;
for (int i = 1; i <= k; i++) {
if (a[i].fi == 0) {
can = false; break;
}
}
if (!can) {
break;
}
int x = 1;
vector<int> cur; cur.pb(1);
for (int i = 1; i <= k; i++) {
a[i].fi--;
cur.pb(a[i].se);
}
ans.pb(cur);
}
for (int i = 1; i <= n; i++) {
if (a[i].fi > 0) {
cout << -1 << "\n"; return;
}
}
cout << sz(ans) << "\n";
for (auto i: ans) {
for (auto j: i) {
cout << j << " ";
}
cout << endl;
}
return;
}
signed main() {
// ios_base::sync_with_stdio(0);
// in; out;
// cin >> TN;
while (TN--) solve();
return 0;
}
Compilation message
nicegift.cpp: In function 'void solve()':
nicegift.cpp:55:13: warning: unused variable 'x' [-Wunused-variable]
int x = 1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
480 KB |
n=4 |
2 |
Correct |
2 ms |
644 KB |
n=3 |
3 |
Correct |
3 ms |
644 KB |
n=3 |
4 |
Correct |
2 ms |
644 KB |
n=4 |
5 |
Correct |
2 ms |
644 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
480 KB |
n=4 |
2 |
Correct |
2 ms |
644 KB |
n=3 |
3 |
Correct |
3 ms |
644 KB |
n=3 |
4 |
Correct |
2 ms |
644 KB |
n=4 |
5 |
Correct |
2 ms |
644 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
7 |
Correct |
2 ms |
644 KB |
n=5 |
8 |
Correct |
5 ms |
1392 KB |
n=8 |
9 |
Correct |
34 ms |
1608 KB |
n=14 |
10 |
Correct |
22 ms |
1608 KB |
n=11 |
11 |
Execution timed out |
2021 ms |
1608 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
480 KB |
n=4 |
2 |
Correct |
2 ms |
644 KB |
n=3 |
3 |
Correct |
3 ms |
644 KB |
n=3 |
4 |
Correct |
2 ms |
644 KB |
n=4 |
5 |
Correct |
2 ms |
644 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
7 |
Correct |
2 ms |
644 KB |
n=5 |
8 |
Correct |
5 ms |
1392 KB |
n=8 |
9 |
Correct |
34 ms |
1608 KB |
n=14 |
10 |
Correct |
22 ms |
1608 KB |
n=11 |
11 |
Execution timed out |
2021 ms |
1608 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2005 ms |
2552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
480 KB |
n=4 |
2 |
Correct |
2 ms |
644 KB |
n=3 |
3 |
Correct |
3 ms |
644 KB |
n=3 |
4 |
Correct |
2 ms |
644 KB |
n=4 |
5 |
Correct |
2 ms |
644 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
7 |
Correct |
2 ms |
644 KB |
n=5 |
8 |
Correct |
5 ms |
1392 KB |
n=8 |
9 |
Correct |
34 ms |
1608 KB |
n=14 |
10 |
Correct |
22 ms |
1608 KB |
n=11 |
11 |
Execution timed out |
2021 ms |
1608 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |