//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios 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 tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 1e6+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
set<pll>st;
pll b[N];
ll a[N];
vector<int> v[N];
void solve(){
ll n , k ,cnt = 0 , kal = 0;
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(a[i] == a[i-1]) kal++;
}
if(kal == n-1){
if(n % k != 0){
cout << "-1\n";
} else {
kal = 1;
cout << n/k <<"\n";
for(int j = 1; j <= n/k; j++){
cout << a[1] <<" ";
for(int i = kal; i < kal+k; i++){
cout << i <<" ";
}
kal += k;
cout << "\n";
}
}
return;
}
for(int i = 1; i <= n; i++){
st.ins({a[i] , i});
}
while(st.sz()){
++cnt;
if(st.sz() < k){
cout << "-1\n";
return;
}
for(int i = 1; i <= k; i++){
b[i] = *st.rbegin();
st.ers(*st.rbegin());
v[cnt].pb(b[i].S);
}
for(int i = 1; i <= k; i++) {
b[i].F--;
if(b[i].F) st.ins({b[i].F , b[i].S});
}
}
cout << cnt <<"\n";
for(int i = 1; i <= cnt; i++){
cout << 1 <<" ";
for(int x : v[i]) cout << x <<" ";
cout << "\n";
}
}
signed main(){
ios;
solve();
return 0;
}
/*
*/
Compilation message
nicegift.cpp: In function 'void solve()':
nicegift.cpp:70:14: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
70 | if(st.sz() < k){
| ~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
n=4 |
2 |
Correct |
15 ms |
23808 KB |
n=3 |
3 |
Correct |
15 ms |
23780 KB |
n=3 |
4 |
Correct |
16 ms |
23700 KB |
n=4 |
5 |
Correct |
14 ms |
23784 KB |
n=4 |
6 |
Correct |
13 ms |
23792 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
n=4 |
2 |
Correct |
15 ms |
23808 KB |
n=3 |
3 |
Correct |
15 ms |
23780 KB |
n=3 |
4 |
Correct |
16 ms |
23700 KB |
n=4 |
5 |
Correct |
14 ms |
23784 KB |
n=4 |
6 |
Correct |
13 ms |
23792 KB |
n=2 |
7 |
Correct |
15 ms |
23764 KB |
n=5 |
8 |
Correct |
17 ms |
24020 KB |
n=8 |
9 |
Correct |
22 ms |
24344 KB |
n=14 |
10 |
Correct |
19 ms |
24124 KB |
n=11 |
11 |
Correct |
65 ms |
28672 KB |
n=50000 |
12 |
Correct |
60 ms |
28760 KB |
n=50000 |
13 |
Correct |
42 ms |
25748 KB |
n=10 |
14 |
Correct |
39 ms |
25608 KB |
n=685 |
15 |
Correct |
41 ms |
25752 KB |
n=623 |
16 |
Correct |
33 ms |
24812 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
n=4 |
2 |
Correct |
15 ms |
23808 KB |
n=3 |
3 |
Correct |
15 ms |
23780 KB |
n=3 |
4 |
Correct |
16 ms |
23700 KB |
n=4 |
5 |
Correct |
14 ms |
23784 KB |
n=4 |
6 |
Correct |
13 ms |
23792 KB |
n=2 |
7 |
Correct |
15 ms |
23764 KB |
n=5 |
8 |
Correct |
17 ms |
24020 KB |
n=8 |
9 |
Correct |
22 ms |
24344 KB |
n=14 |
10 |
Correct |
19 ms |
24124 KB |
n=11 |
11 |
Correct |
65 ms |
28672 KB |
n=50000 |
12 |
Correct |
60 ms |
28760 KB |
n=50000 |
13 |
Correct |
42 ms |
25748 KB |
n=10 |
14 |
Correct |
39 ms |
25608 KB |
n=685 |
15 |
Correct |
41 ms |
25752 KB |
n=623 |
16 |
Correct |
33 ms |
24812 KB |
n=973 |
17 |
Correct |
48 ms |
25228 KB |
n=989 |
18 |
Correct |
27 ms |
24388 KB |
n=563 |
19 |
Correct |
42 ms |
24768 KB |
n=592 |
20 |
Correct |
37 ms |
24724 KB |
n=938 |
21 |
Correct |
30 ms |
24656 KB |
n=747 |
22 |
Correct |
35 ms |
24584 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
46072 KB |
n=1000000 |
2 |
Correct |
175 ms |
46028 KB |
n=666666 |
3 |
Correct |
103 ms |
36264 KB |
n=400000 |
4 |
Incorrect |
50 ms |
29860 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
n=4 |
2 |
Correct |
15 ms |
23808 KB |
n=3 |
3 |
Correct |
15 ms |
23780 KB |
n=3 |
4 |
Correct |
16 ms |
23700 KB |
n=4 |
5 |
Correct |
14 ms |
23784 KB |
n=4 |
6 |
Correct |
13 ms |
23792 KB |
n=2 |
7 |
Correct |
15 ms |
23764 KB |
n=5 |
8 |
Correct |
17 ms |
24020 KB |
n=8 |
9 |
Correct |
22 ms |
24344 KB |
n=14 |
10 |
Correct |
19 ms |
24124 KB |
n=11 |
11 |
Correct |
65 ms |
28672 KB |
n=50000 |
12 |
Correct |
60 ms |
28760 KB |
n=50000 |
13 |
Correct |
42 ms |
25748 KB |
n=10 |
14 |
Correct |
39 ms |
25608 KB |
n=685 |
15 |
Correct |
41 ms |
25752 KB |
n=623 |
16 |
Correct |
33 ms |
24812 KB |
n=973 |
17 |
Correct |
48 ms |
25228 KB |
n=989 |
18 |
Correct |
27 ms |
24388 KB |
n=563 |
19 |
Correct |
42 ms |
24768 KB |
n=592 |
20 |
Correct |
37 ms |
24724 KB |
n=938 |
21 |
Correct |
30 ms |
24656 KB |
n=747 |
22 |
Correct |
35 ms |
24584 KB |
n=991 |
23 |
Correct |
293 ms |
46072 KB |
n=1000000 |
24 |
Correct |
175 ms |
46028 KB |
n=666666 |
25 |
Correct |
103 ms |
36264 KB |
n=400000 |
26 |
Incorrect |
50 ms |
29860 KB |
Jury has the answer but participant has not |
27 |
Halted |
0 ms |
0 KB |
- |