//#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define sqr(x) (x) * (x)
using namespace std;
using namespace __gnu_pbds;
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
priority_queue <pair <ll, int>> a;
ll sum = 0;
for(int i = 0; i < n; ++i)
{
int x;
cin >> x;
sum += x;
if (x > 0) a.push({x, i});
}
// if (sum % k > 0)
// {
// cout << -1;
// return 0;
// }
vector <pair <ll, vector <int>>> ans;
vector <int> cl;
while(int(a.size()) >= k)
{
ans.pb({1, cl});
vector <pair <ll, int>> ps;
for(int i = 0; i < k; ++i)
{
pair <ll, int> pp = a.top();
a.pop();
ans.back().S.pb(pp.S);
pp.F--;
if (pp.F > 0) ps.pb(pp);
}
for(pair <ll, int> j : ps)
a.push(j);
}
if (!a.empty())
{
cout << -1;
}
else
{
cout << int(ans.size()) << '\n';
for(int i = 0; i < int(ans.size()); ++i)
{
cout << ans[i].F << ' ';
for(int j = 0; j < k; ++j)
cout << ans[i].S[j] + 1 << ' ';
cout << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
5 ms |
1144 KB |
n=8 |
9 |
Correct |
12 ms |
1392 KB |
n=14 |
10 |
Correct |
7 ms |
1144 KB |
n=11 |
11 |
Correct |
49 ms |
5104 KB |
n=50000 |
12 |
Correct |
44 ms |
5112 KB |
n=50000 |
13 |
Correct |
33 ms |
3948 KB |
n=10 |
14 |
Correct |
36 ms |
3400 KB |
n=685 |
15 |
Correct |
37 ms |
3808 KB |
n=623 |
16 |
Correct |
24 ms |
2288 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
5 ms |
1144 KB |
n=8 |
9 |
Correct |
12 ms |
1392 KB |
n=14 |
10 |
Correct |
7 ms |
1144 KB |
n=11 |
11 |
Correct |
49 ms |
5104 KB |
n=50000 |
12 |
Correct |
44 ms |
5112 KB |
n=50000 |
13 |
Correct |
33 ms |
3948 KB |
n=10 |
14 |
Correct |
36 ms |
3400 KB |
n=685 |
15 |
Correct |
37 ms |
3808 KB |
n=623 |
16 |
Correct |
24 ms |
2288 KB |
n=973 |
17 |
Correct |
37 ms |
2792 KB |
n=989 |
18 |
Correct |
18 ms |
1140 KB |
n=563 |
19 |
Correct |
26 ms |
1524 KB |
n=592 |
20 |
Correct |
27 ms |
1396 KB |
n=938 |
21 |
Correct |
23 ms |
1396 KB |
n=747 |
22 |
Correct |
24 ms |
1396 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2053 ms |
241680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
5 ms |
1144 KB |
n=8 |
9 |
Correct |
12 ms |
1392 KB |
n=14 |
10 |
Correct |
7 ms |
1144 KB |
n=11 |
11 |
Correct |
49 ms |
5104 KB |
n=50000 |
12 |
Correct |
44 ms |
5112 KB |
n=50000 |
13 |
Correct |
33 ms |
3948 KB |
n=10 |
14 |
Correct |
36 ms |
3400 KB |
n=685 |
15 |
Correct |
37 ms |
3808 KB |
n=623 |
16 |
Correct |
24 ms |
2288 KB |
n=973 |
17 |
Correct |
37 ms |
2792 KB |
n=989 |
18 |
Correct |
18 ms |
1140 KB |
n=563 |
19 |
Correct |
26 ms |
1524 KB |
n=592 |
20 |
Correct |
27 ms |
1396 KB |
n=938 |
21 |
Correct |
23 ms |
1396 KB |
n=747 |
22 |
Correct |
24 ms |
1396 KB |
n=991 |
23 |
Execution timed out |
2053 ms |
241680 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |