#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],cur;
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];
int sum=0;
rep(n) sum+=a[i];
if(sum<=100000){
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";
}
return 0;
}
cur=0;
if(a[0]*n%k){
cout << "-1\n";
return 0;
}
rep(n){
res.pb({0});
rep1(j,k) res.back().pb(cur+1),cur=(cur+1)%n;
if(cur==0) break;
}
for(auto& vec1: res) vec1[0]=a[0]*n/k/sz(res);
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 |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
0 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 |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
4 ms |
1132 KB |
n=8 |
9 |
Correct |
12 ms |
1448 KB |
n=14 |
10 |
Correct |
6 ms |
1132 KB |
n=11 |
11 |
Correct |
47 ms |
5860 KB |
n=50000 |
12 |
Correct |
42 ms |
5732 KB |
n=50000 |
13 |
Correct |
30 ms |
4256 KB |
n=10 |
14 |
Correct |
30 ms |
3872 KB |
n=685 |
15 |
Correct |
32 ms |
4128 KB |
n=623 |
16 |
Correct |
20 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 |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
4 ms |
1132 KB |
n=8 |
9 |
Correct |
12 ms |
1448 KB |
n=14 |
10 |
Correct |
6 ms |
1132 KB |
n=11 |
11 |
Correct |
47 ms |
5860 KB |
n=50000 |
12 |
Correct |
42 ms |
5732 KB |
n=50000 |
13 |
Correct |
30 ms |
4256 KB |
n=10 |
14 |
Correct |
30 ms |
3872 KB |
n=685 |
15 |
Correct |
32 ms |
4128 KB |
n=623 |
16 |
Correct |
20 ms |
2468 KB |
n=973 |
17 |
Correct |
28 ms |
3108 KB |
n=989 |
18 |
Correct |
13 ms |
1644 KB |
n=563 |
19 |
Correct |
20 ms |
2028 KB |
n=592 |
20 |
Correct |
21 ms |
1772 KB |
n=938 |
21 |
Correct |
17 ms |
1772 KB |
n=747 |
22 |
Correct |
18 ms |
1644 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
58144 KB |
n=1000000 |
2 |
Correct |
254 ms |
29200 KB |
n=666666 |
3 |
Correct |
137 ms |
15516 KB |
n=400000 |
4 |
Correct |
358 ms |
49192 KB |
n=285714 |
5 |
Correct |
6 ms |
876 KB |
n=20000 |
6 |
Correct |
310 ms |
47120 KB |
n=181818 |
7 |
Correct |
3 ms |
620 KB |
n=10000 |
8 |
Correct |
36 ms |
6508 KB |
n=6666 |
9 |
Correct |
2 ms |
492 KB |
n=4000 |
10 |
Correct |
204 ms |
32748 KB |
n=2857 |
11 |
Correct |
1 ms |
364 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
4 ms |
1132 KB |
n=8 |
9 |
Correct |
12 ms |
1448 KB |
n=14 |
10 |
Correct |
6 ms |
1132 KB |
n=11 |
11 |
Correct |
47 ms |
5860 KB |
n=50000 |
12 |
Correct |
42 ms |
5732 KB |
n=50000 |
13 |
Correct |
30 ms |
4256 KB |
n=10 |
14 |
Correct |
30 ms |
3872 KB |
n=685 |
15 |
Correct |
32 ms |
4128 KB |
n=623 |
16 |
Correct |
20 ms |
2468 KB |
n=973 |
17 |
Correct |
28 ms |
3108 KB |
n=989 |
18 |
Correct |
13 ms |
1644 KB |
n=563 |
19 |
Correct |
20 ms |
2028 KB |
n=592 |
20 |
Correct |
21 ms |
1772 KB |
n=938 |
21 |
Correct |
17 ms |
1772 KB |
n=747 |
22 |
Correct |
18 ms |
1644 KB |
n=991 |
23 |
Correct |
440 ms |
58144 KB |
n=1000000 |
24 |
Correct |
254 ms |
29200 KB |
n=666666 |
25 |
Correct |
137 ms |
15516 KB |
n=400000 |
26 |
Correct |
358 ms |
49192 KB |
n=285714 |
27 |
Correct |
6 ms |
876 KB |
n=20000 |
28 |
Correct |
310 ms |
47120 KB |
n=181818 |
29 |
Correct |
3 ms |
620 KB |
n=10000 |
30 |
Correct |
36 ms |
6508 KB |
n=6666 |
31 |
Correct |
2 ms |
492 KB |
n=4000 |
32 |
Correct |
204 ms |
32748 KB |
n=2857 |
33 |
Correct |
1 ms |
364 KB |
n=2000 |
34 |
Incorrect |
8 ms |
1576 KB |
Taken too much stones from the heap |
35 |
Halted |
0 ms |
0 KB |
- |