#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;
pair<ll, ll> a[1000100];
vector<pair<ll, vector<ll> > > v;
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;
cin>>n>>k;
for(ll i=1; i<=n; i++)
{
cin>>a[i].fr;
a[i].se=i;
}
sort(a+1, a+1+n);
while(a[n].fr)
{
vector<ll> q;
/*for(ll i=1; i<=n; i++)
cout<<a[i].fr<<" ";
cout<<endl;*/
if(!a[n-k+1].fr)
{
cout<<-1;
return 0;
}
for(ll j=n; j>n-k+1; j--)
{
q.push_back(a[j].se);
a[j].fr-=a[n-k+1].fr;
}
q.push_back(a[n-k+1].se);
v.push_back({a[n-k+1].fr, q});
a[n-k+1].fr-=a[n-k+1].fr;
sort(a+1, a+1+n);
}
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:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=0; i<v.size(); i++)
~^~~~~~~~~
nicegift.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll j=0; j<v[i].se.size(); j++)
~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
468 KB |
n=3 |
3 |
Correct |
2 ms |
504 KB |
n=3 |
4 |
Correct |
2 ms |
636 KB |
n=4 |
5 |
Correct |
2 ms |
640 KB |
n=4 |
6 |
Correct |
2 ms |
640 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
468 KB |
n=3 |
3 |
Correct |
2 ms |
504 KB |
n=3 |
4 |
Correct |
2 ms |
636 KB |
n=4 |
5 |
Correct |
2 ms |
640 KB |
n=4 |
6 |
Correct |
2 ms |
640 KB |
n=2 |
7 |
Correct |
2 ms |
640 KB |
n=5 |
8 |
Correct |
2 ms |
640 KB |
n=8 |
9 |
Incorrect |
2 ms |
640 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
468 KB |
n=3 |
3 |
Correct |
2 ms |
504 KB |
n=3 |
4 |
Correct |
2 ms |
636 KB |
n=4 |
5 |
Correct |
2 ms |
640 KB |
n=4 |
6 |
Correct |
2 ms |
640 KB |
n=2 |
7 |
Correct |
2 ms |
640 KB |
n=5 |
8 |
Correct |
2 ms |
640 KB |
n=8 |
9 |
Incorrect |
2 ms |
640 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2035 ms |
16148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
468 KB |
n=3 |
3 |
Correct |
2 ms |
504 KB |
n=3 |
4 |
Correct |
2 ms |
636 KB |
n=4 |
5 |
Correct |
2 ms |
640 KB |
n=4 |
6 |
Correct |
2 ms |
640 KB |
n=2 |
7 |
Correct |
2 ms |
640 KB |
n=5 |
8 |
Correct |
2 ms |
640 KB |
n=8 |
9 |
Incorrect |
2 ms |
640 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |