#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> void vout(T s){cout << s << endl;exit(0);}
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector <ll> a(n);
set <pll> st;
ll sc = 0, mx = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
st.insert({a[i], i});
sc += a[i];
mx = max(mx, a[i]);
}
if(sc % k)vout(-1);
if(sc < mx)vout(-1);
// pll fufel = *--st.end();
// st.erase(--st.end());
// sc -= mx;
vector < pair<ll, vector <ll> > > ans;
while(1){
vector <pll> V;
if(st.empty())break;
ll Mx = (--st.end()) -> fi;
if(sc - Mx == Mx)break;
if(sc - Mx < Mx)vout(-1);
for(int i = 0; i < k; i++){
if(st.empty())vout(-1);
pll xe = *--st.end();
V.p_b(xe);
st.erase(--st.end());
}
sc -= k;
vector <ll> c;
for(auto i : V)c.p_b(i.se);
ans.p_b({1, c});
for(auto i : V){
if(i.fi > 1)st.insert({i.fi - 1, i.se});
}
c.clear();
V.clear();
}
if(!st.empty()){
pll fufel = *--st.end();
st.erase(--st.end());
while(!st.empty()){
vector <pll> V;
for(int i = 1; i < k; i++){
if(st.empty())vout(-1);
pll xe = *--st.end();
V.p_b(xe);
st.erase(--st.end());
}
sc -= k;
vector <ll> c;
for(auto i : V)c.p_b(i.se);
c.p_b(fufel.se);
ans.p_b({1, c});
for(auto i : V){
if(i.fi > 1)st.insert({i.fi - 1, i.se});
}
c.clear();
V.clear();
}
}
cout << ans.size() << "\n";
for(auto i : ans){
cout << i.fi;
for(auto j : i.se)cout << " " << j + 1;
cout << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
252 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
3 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 |
3 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
252 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
3 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
504 KB |
n=8 |
9 |
Correct |
12 ms |
1268 KB |
n=14 |
10 |
Correct |
9 ms |
1144 KB |
n=11 |
11 |
Correct |
61 ms |
7040 KB |
n=50000 |
12 |
Correct |
60 ms |
7044 KB |
n=50000 |
13 |
Correct |
39 ms |
3816 KB |
n=10 |
14 |
Correct |
39 ms |
3500 KB |
n=685 |
15 |
Correct |
42 ms |
3684 KB |
n=623 |
16 |
Correct |
25 ms |
2284 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
252 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
3 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
504 KB |
n=8 |
9 |
Correct |
12 ms |
1268 KB |
n=14 |
10 |
Correct |
9 ms |
1144 KB |
n=11 |
11 |
Correct |
61 ms |
7040 KB |
n=50000 |
12 |
Correct |
60 ms |
7044 KB |
n=50000 |
13 |
Correct |
39 ms |
3816 KB |
n=10 |
14 |
Correct |
39 ms |
3500 KB |
n=685 |
15 |
Correct |
42 ms |
3684 KB |
n=623 |
16 |
Correct |
25 ms |
2284 KB |
n=973 |
17 |
Correct |
42 ms |
2824 KB |
n=989 |
18 |
Correct |
18 ms |
1268 KB |
n=563 |
19 |
Correct |
29 ms |
1648 KB |
n=592 |
20 |
Correct |
33 ms |
1736 KB |
n=938 |
21 |
Correct |
23 ms |
1524 KB |
n=747 |
22 |
Correct |
28 ms |
1712 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2025 ms |
170372 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
252 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
3 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
504 KB |
n=8 |
9 |
Correct |
12 ms |
1268 KB |
n=14 |
10 |
Correct |
9 ms |
1144 KB |
n=11 |
11 |
Correct |
61 ms |
7040 KB |
n=50000 |
12 |
Correct |
60 ms |
7044 KB |
n=50000 |
13 |
Correct |
39 ms |
3816 KB |
n=10 |
14 |
Correct |
39 ms |
3500 KB |
n=685 |
15 |
Correct |
42 ms |
3684 KB |
n=623 |
16 |
Correct |
25 ms |
2284 KB |
n=973 |
17 |
Correct |
42 ms |
2824 KB |
n=989 |
18 |
Correct |
18 ms |
1268 KB |
n=563 |
19 |
Correct |
29 ms |
1648 KB |
n=592 |
20 |
Correct |
33 ms |
1736 KB |
n=938 |
21 |
Correct |
23 ms |
1524 KB |
n=747 |
22 |
Correct |
28 ms |
1712 KB |
n=991 |
23 |
Execution timed out |
2025 ms |
170372 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |