#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define itr iterator
typedef pair<int,int> pii;
const int MAX=5e6;
set<pii> st;
set<pii>::itr it_1,it_2;
vector<int> res;
int N,K,sum,arr[MAX];
void print_1()
{
assert(!(st.size()%K));
while(!st.empty())
{
res.pb(st.begin()->second);
st.erase(st.begin());
}
cout<<res.size()/K<<"\n";
for(int A=0;A<res.size();A+=K)
{
cout<<1<<" ";
for(int B=A;B<A+K;B++)
cout<<res[B]<<" ";
cout<<"\n";
}
return ;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin>>N>>K;
for(int A=1;A<=N;A++)
{
cin>>arr[A];
sum+=arr[A];
if(arr[A])
st.insert(mp(-arr[A],A));
}
if(sum%K)
return cout<<-1,0;
vector<pii> lol(K);
while(true)
{
if(st.size()<K)
return cout<<-1,0;
if(st.begin()->first==-1)
{
print_1();
break;
}
for(int A=0;A<K;A++)
{
lol[A]=*st.begin();
st.erase(st.begin());
}
for(int A=0;A<K;A++)
{
lol[A].first++;
if(lol[A].first!=0)
st.insert(lol[A]);
res.pb(lol[A].second);
}
/*for(auto A:st)
cout<<-A.first<<" ";
cout<<"\n";*/
}
return 0;
}
Compilation message
nicegift.cpp: In function 'void print_1()':
nicegift.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int A=0;A<res.size();A+=K)
~^~~~~~~~~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:57:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(st.size()<K)
~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
468 KB |
n=3 |
3 |
Correct |
2 ms |
476 KB |
n=3 |
4 |
Correct |
2 ms |
492 KB |
n=4 |
5 |
Correct |
2 ms |
532 KB |
n=4 |
6 |
Correct |
2 ms |
704 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 |
476 KB |
n=3 |
4 |
Correct |
2 ms |
492 KB |
n=4 |
5 |
Correct |
2 ms |
532 KB |
n=4 |
6 |
Correct |
2 ms |
704 KB |
n=2 |
7 |
Correct |
2 ms |
704 KB |
n=5 |
8 |
Correct |
4 ms |
964 KB |
n=8 |
9 |
Correct |
9 ms |
964 KB |
n=14 |
10 |
Correct |
6 ms |
964 KB |
n=11 |
11 |
Correct |
45 ms |
5708 KB |
n=50000 |
12 |
Correct |
49 ms |
5720 KB |
n=50000 |
13 |
Correct |
27 ms |
5720 KB |
n=10 |
14 |
Correct |
27 ms |
5720 KB |
n=685 |
15 |
Correct |
29 ms |
5720 KB |
n=623 |
16 |
Correct |
18 ms |
5720 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
468 KB |
n=3 |
3 |
Correct |
2 ms |
476 KB |
n=3 |
4 |
Correct |
2 ms |
492 KB |
n=4 |
5 |
Correct |
2 ms |
532 KB |
n=4 |
6 |
Correct |
2 ms |
704 KB |
n=2 |
7 |
Correct |
2 ms |
704 KB |
n=5 |
8 |
Correct |
4 ms |
964 KB |
n=8 |
9 |
Correct |
9 ms |
964 KB |
n=14 |
10 |
Correct |
6 ms |
964 KB |
n=11 |
11 |
Correct |
45 ms |
5708 KB |
n=50000 |
12 |
Correct |
49 ms |
5720 KB |
n=50000 |
13 |
Correct |
27 ms |
5720 KB |
n=10 |
14 |
Correct |
27 ms |
5720 KB |
n=685 |
15 |
Correct |
29 ms |
5720 KB |
n=623 |
16 |
Correct |
18 ms |
5720 KB |
n=973 |
17 |
Correct |
40 ms |
5720 KB |
n=989 |
18 |
Correct |
18 ms |
5720 KB |
n=563 |
19 |
Correct |
28 ms |
5720 KB |
n=592 |
20 |
Correct |
24 ms |
5720 KB |
n=938 |
21 |
Correct |
18 ms |
5720 KB |
n=747 |
22 |
Correct |
22 ms |
5720 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2049 ms |
104296 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 |
476 KB |
n=3 |
4 |
Correct |
2 ms |
492 KB |
n=4 |
5 |
Correct |
2 ms |
532 KB |
n=4 |
6 |
Correct |
2 ms |
704 KB |
n=2 |
7 |
Correct |
2 ms |
704 KB |
n=5 |
8 |
Correct |
4 ms |
964 KB |
n=8 |
9 |
Correct |
9 ms |
964 KB |
n=14 |
10 |
Correct |
6 ms |
964 KB |
n=11 |
11 |
Correct |
45 ms |
5708 KB |
n=50000 |
12 |
Correct |
49 ms |
5720 KB |
n=50000 |
13 |
Correct |
27 ms |
5720 KB |
n=10 |
14 |
Correct |
27 ms |
5720 KB |
n=685 |
15 |
Correct |
29 ms |
5720 KB |
n=623 |
16 |
Correct |
18 ms |
5720 KB |
n=973 |
17 |
Correct |
40 ms |
5720 KB |
n=989 |
18 |
Correct |
18 ms |
5720 KB |
n=563 |
19 |
Correct |
28 ms |
5720 KB |
n=592 |
20 |
Correct |
24 ms |
5720 KB |
n=938 |
21 |
Correct |
18 ms |
5720 KB |
n=747 |
22 |
Correct |
22 ms |
5720 KB |
n=991 |
23 |
Execution timed out |
2049 ms |
104296 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |