#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 1e5 + 10;
bool cmp(pii a, pii b)
{
return a > b;
}
void solve()
{
int n, k;
cin >> n >> k;
vec<int> a(n + 1);
set<pii, decltype(cmp)*> setik(cmp);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
setik.insert({a[i], i});
}
vec<vec<int>> operations;
while (sz(setik) >= k)
{
vec<int> op = {1};
for (int i = 0; i < k; i++)
{
pii cur = *setik.begin(); setik.erase(setik.begin());
op.pb(cur.s);
cur.f--;
if (cur.f != 0) setik.insert(cur);
}
operations.pb(op);
}
if (sz(setik) != 0)
{
cout << -1;
return;
}
cout << sz(operations) << "\n";
for (auto &operation : operations)
{
for (auto &x : operation) cout << x << " ";
cout << "\n";
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
340 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Incorrect |
1 ms |
212 KB |
Same heap occurs twice |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
340 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Incorrect |
1 ms |
212 KB |
Same heap occurs twice |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
340 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Incorrect |
1 ms |
212 KB |
Same heap occurs twice |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2077 ms |
248716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
340 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Incorrect |
1 ms |
212 KB |
Same heap occurs twice |
5 |
Halted |
0 ms |
0 KB |
- |