#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<b; ++i)
#define rep3(i,a,b) for(int i=a; i>=b; --i)
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define pii pair<int,int>
#define pb push_back
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&... y){cerr << x << ' ',_do(y...);}
#else
#define bug(...) 826
#endif
const int maxn=1000005;
const int mod=1000000007;
int n,k,a[maxn];
priority_queue<pii> pq;
vector<vector<int>> res;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> n >> k;
rep(n) cin >> a[i];
rep(n) pq.push({a[i],i});
while(sz(pq)>=k){
vector<int> vec;
rep(k){
auto [x,y]=pq.top();
pq.pop();
vec.pb(y);
}
res.pb({1});
for(auto i: vec) res.back().pb(i+1);
for(auto i: vec) a[i]--;
for(auto i: vec) if(a[i]) pq.push({a[i],i});
}
if(!pq.empty()){
cout << "-1\n";
return 0;
}
cout << sz(res) << "\n";
for(auto& vec1: res){
for(auto i: vec1) cout << i << ' ';
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
3 ms |
1132 KB |
n=8 |
9 |
Correct |
9 ms |
1448 KB |
n=14 |
10 |
Correct |
6 ms |
1132 KB |
n=11 |
11 |
Correct |
49 ms |
5860 KB |
n=50000 |
12 |
Correct |
43 ms |
5860 KB |
n=50000 |
13 |
Correct |
29 ms |
4256 KB |
n=10 |
14 |
Correct |
29 ms |
3744 KB |
n=685 |
15 |
Correct |
32 ms |
4128 KB |
n=623 |
16 |
Correct |
18 ms |
2468 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
3 ms |
1132 KB |
n=8 |
9 |
Correct |
9 ms |
1448 KB |
n=14 |
10 |
Correct |
6 ms |
1132 KB |
n=11 |
11 |
Correct |
49 ms |
5860 KB |
n=50000 |
12 |
Correct |
43 ms |
5860 KB |
n=50000 |
13 |
Correct |
29 ms |
4256 KB |
n=10 |
14 |
Correct |
29 ms |
3744 KB |
n=685 |
15 |
Correct |
32 ms |
4128 KB |
n=623 |
16 |
Correct |
18 ms |
2468 KB |
n=973 |
17 |
Correct |
28 ms |
3108 KB |
n=989 |
18 |
Correct |
16 ms |
1644 KB |
n=563 |
19 |
Correct |
20 ms |
2028 KB |
n=592 |
20 |
Correct |
25 ms |
1772 KB |
n=938 |
21 |
Correct |
16 ms |
1772 KB |
n=747 |
22 |
Correct |
17 ms |
1644 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2081 ms |
280332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
3 ms |
1132 KB |
n=8 |
9 |
Correct |
9 ms |
1448 KB |
n=14 |
10 |
Correct |
6 ms |
1132 KB |
n=11 |
11 |
Correct |
49 ms |
5860 KB |
n=50000 |
12 |
Correct |
43 ms |
5860 KB |
n=50000 |
13 |
Correct |
29 ms |
4256 KB |
n=10 |
14 |
Correct |
29 ms |
3744 KB |
n=685 |
15 |
Correct |
32 ms |
4128 KB |
n=623 |
16 |
Correct |
18 ms |
2468 KB |
n=973 |
17 |
Correct |
28 ms |
3108 KB |
n=989 |
18 |
Correct |
16 ms |
1644 KB |
n=563 |
19 |
Correct |
20 ms |
2028 KB |
n=592 |
20 |
Correct |
25 ms |
1772 KB |
n=938 |
21 |
Correct |
16 ms |
1772 KB |
n=747 |
22 |
Correct |
17 ms |
1644 KB |
n=991 |
23 |
Execution timed out |
2081 ms |
280332 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |