#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define st string
#define fr first
#define se second
const ll mod=1e9+7;
using namespace std;
set<pair<ll, ll> > a;
vector<pair<ll, vector<ll> > > v;
map<ll, ll> us;
int main()
{
//freopen("1.txt", "r", stdin);
//freopen("1.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll n, k, s=0, f;
cin>>n>>k;
for(ll i=1; i<=n; i++)
{
ll x;
cin>>x;
us[x]++;
a.insert({x, i});
f=x;
s+=x;
}
if(us[f]!=n)
{
f=1;
}
if(s%k!=0)
{
cout<<-1;
return 0;
}
while(a.size()>=k)
{
std::vector<ll> q;
std::vector<pair<ll, ll> > y;
for(ll i=1; i<=k; i++)
{
//cout<<i<<" "<<a.size()<<endl;
std::pair<ll, ll> x;
x=*a.rbegin();
a.erase(*a.rbegin());
q.push_back(x.se);
x.fr-=f;
if(x.fr)
y.push_back(x);
}
for(ll i=0; i<y.size(); i++)
{
a.insert(y[i]);
//cout<<"y="<<y[i].fr<<" "<<y[i].se<<endl;
}
v.push_back({f, q});
}
if(a.size()>0)
{
cout<<-1;
return 0;
}
cout<<v.size()<<endl;
for(ll i=0; i<v.size(); i++)
{
cout<<v[i].fr<<" ";
for(ll j=0; j<v[i].se.size(); j++)
{
cout<<v[i].se[j]<<" ";
}
cout<<endl;
}
return 0;
}
/*
*/
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(a.size()>=k)
~~~~~~~~^~~
nicegift.cpp:68:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=0; i<y.size(); i++)
~^~~~~~~~~
nicegift.cpp:84:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=0; i<v.size(); i++)
~^~~~~~~~~
nicegift.cpp:87:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll j=0; j<v[i].se.size(); j++)
~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
576 KB |
n=3 |
4 |
Correct |
2 ms |
576 KB |
n=4 |
5 |
Correct |
2 ms |
576 KB |
n=4 |
6 |
Correct |
2 ms |
592 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
576 KB |
n=3 |
4 |
Correct |
2 ms |
576 KB |
n=4 |
5 |
Correct |
2 ms |
576 KB |
n=4 |
6 |
Correct |
2 ms |
592 KB |
n=2 |
7 |
Correct |
2 ms |
620 KB |
n=5 |
8 |
Correct |
7 ms |
1388 KB |
n=8 |
9 |
Correct |
34 ms |
1640 KB |
n=14 |
10 |
Correct |
22 ms |
1640 KB |
n=11 |
11 |
Correct |
147 ms |
6664 KB |
n=50000 |
12 |
Correct |
147 ms |
6784 KB |
n=50000 |
13 |
Correct |
116 ms |
6784 KB |
n=10 |
14 |
Correct |
105 ms |
6784 KB |
n=685 |
15 |
Correct |
114 ms |
6784 KB |
n=623 |
16 |
Correct |
65 ms |
6784 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
576 KB |
n=3 |
4 |
Correct |
2 ms |
576 KB |
n=4 |
5 |
Correct |
2 ms |
576 KB |
n=4 |
6 |
Correct |
2 ms |
592 KB |
n=2 |
7 |
Correct |
2 ms |
620 KB |
n=5 |
8 |
Correct |
7 ms |
1388 KB |
n=8 |
9 |
Correct |
34 ms |
1640 KB |
n=14 |
10 |
Correct |
22 ms |
1640 KB |
n=11 |
11 |
Correct |
147 ms |
6664 KB |
n=50000 |
12 |
Correct |
147 ms |
6784 KB |
n=50000 |
13 |
Correct |
116 ms |
6784 KB |
n=10 |
14 |
Correct |
105 ms |
6784 KB |
n=685 |
15 |
Correct |
114 ms |
6784 KB |
n=623 |
16 |
Correct |
65 ms |
6784 KB |
n=973 |
17 |
Correct |
92 ms |
6784 KB |
n=989 |
18 |
Correct |
45 ms |
6784 KB |
n=563 |
19 |
Correct |
37 ms |
6784 KB |
n=592 |
20 |
Correct |
42 ms |
6784 KB |
n=938 |
21 |
Correct |
36 ms |
6784 KB |
n=747 |
22 |
Correct |
38 ms |
6784 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1870 ms |
93256 KB |
n=1000000 |
2 |
Correct |
1059 ms |
93256 KB |
n=666666 |
3 |
Correct |
525 ms |
93256 KB |
n=400000 |
4 |
Incorrect |
245 ms |
93256 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
576 KB |
n=3 |
4 |
Correct |
2 ms |
576 KB |
n=4 |
5 |
Correct |
2 ms |
576 KB |
n=4 |
6 |
Correct |
2 ms |
592 KB |
n=2 |
7 |
Correct |
2 ms |
620 KB |
n=5 |
8 |
Correct |
7 ms |
1388 KB |
n=8 |
9 |
Correct |
34 ms |
1640 KB |
n=14 |
10 |
Correct |
22 ms |
1640 KB |
n=11 |
11 |
Correct |
147 ms |
6664 KB |
n=50000 |
12 |
Correct |
147 ms |
6784 KB |
n=50000 |
13 |
Correct |
116 ms |
6784 KB |
n=10 |
14 |
Correct |
105 ms |
6784 KB |
n=685 |
15 |
Correct |
114 ms |
6784 KB |
n=623 |
16 |
Correct |
65 ms |
6784 KB |
n=973 |
17 |
Correct |
92 ms |
6784 KB |
n=989 |
18 |
Correct |
45 ms |
6784 KB |
n=563 |
19 |
Correct |
37 ms |
6784 KB |
n=592 |
20 |
Correct |
42 ms |
6784 KB |
n=938 |
21 |
Correct |
36 ms |
6784 KB |
n=747 |
22 |
Correct |
38 ms |
6784 KB |
n=991 |
23 |
Correct |
1870 ms |
93256 KB |
n=1000000 |
24 |
Correct |
1059 ms |
93256 KB |
n=666666 |
25 |
Correct |
525 ms |
93256 KB |
n=400000 |
26 |
Incorrect |
245 ms |
93256 KB |
Jury has the answer but participant has not |
27 |
Halted |
0 ms |
0 KB |
- |