#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define int long long
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 1e5+777;
const int MOD = 1e9+7;
int n, k, a[E], sum;
vector<vector<int>> res;
priority_queue<pair<int,int>> pq;
signed main(){auto solve=[&](){
cin >> n >> k;
for(int i = 1; i <= n; ++i){
cin >> a[i];
sum += a[i];
if(a[i] > 0){
pq.push({a[i], i});
}
}
bool ok = (sum % k == 0);
for(int i = 1; i <= n; ++i){
if(a[i] > sum / k) ok = false;
}
if(!ok){
cout << -1;
return;
}
while(sz(pq)){
vector<pair<int,int>> c;
vector<int> r;
for(int i = 0; i < k; ++i){
c.pb(pq.top());
pq.pop();
--c[i].F;
r.pb(c[i].S);
}
for(int i = 0; i < k; ++i){
if(c[i].F > 0){
pq.push(c[i]);
}
}
res.pb(r);
}
cout << sz(res) << '\n';
for(auto v : res){
cout << 1 << ' ';
for(auto it : v)
cout << it << ' ';
cout << '\n';
}
};NFS;solve();}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
8 ms |
1160 KB |
n=14 |
10 |
Correct |
5 ms |
972 KB |
n=11 |
11 |
Correct |
39 ms |
5028 KB |
n=50000 |
12 |
Correct |
47 ms |
5060 KB |
n=50000 |
13 |
Correct |
24 ms |
3428 KB |
n=10 |
14 |
Correct |
23 ms |
3064 KB |
n=685 |
15 |
Correct |
25 ms |
3348 KB |
n=623 |
16 |
Correct |
15 ms |
1924 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
8 ms |
1160 KB |
n=14 |
10 |
Correct |
5 ms |
972 KB |
n=11 |
11 |
Correct |
39 ms |
5028 KB |
n=50000 |
12 |
Correct |
47 ms |
5060 KB |
n=50000 |
13 |
Correct |
24 ms |
3428 KB |
n=10 |
14 |
Correct |
23 ms |
3064 KB |
n=685 |
15 |
Correct |
25 ms |
3348 KB |
n=623 |
16 |
Correct |
15 ms |
1924 KB |
n=973 |
17 |
Correct |
25 ms |
2472 KB |
n=989 |
18 |
Correct |
13 ms |
1220 KB |
n=563 |
19 |
Correct |
18 ms |
1568 KB |
n=592 |
20 |
Correct |
16 ms |
1600 KB |
n=938 |
21 |
Correct |
13 ms |
1356 KB |
n=747 |
22 |
Correct |
15 ms |
1484 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2095 ms |
352208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
8 ms |
1160 KB |
n=14 |
10 |
Correct |
5 ms |
972 KB |
n=11 |
11 |
Correct |
39 ms |
5028 KB |
n=50000 |
12 |
Correct |
47 ms |
5060 KB |
n=50000 |
13 |
Correct |
24 ms |
3428 KB |
n=10 |
14 |
Correct |
23 ms |
3064 KB |
n=685 |
15 |
Correct |
25 ms |
3348 KB |
n=623 |
16 |
Correct |
15 ms |
1924 KB |
n=973 |
17 |
Correct |
25 ms |
2472 KB |
n=989 |
18 |
Correct |
13 ms |
1220 KB |
n=563 |
19 |
Correct |
18 ms |
1568 KB |
n=592 |
20 |
Correct |
16 ms |
1600 KB |
n=938 |
21 |
Correct |
13 ms |
1356 KB |
n=747 |
22 |
Correct |
15 ms |
1484 KB |
n=991 |
23 |
Execution timed out |
2095 ms |
352208 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |