#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,looper;
int N,K,sum,arr[MAX];
void print_1()
{
assert(!(st.size()%K));
for(int A=0;A<st.size()/K;A++)
looper.pb(-st.begin()->first);
while(!st.empty())
{
res.pb(st.begin()->second);
st.erase(st.begin());
}
cout<<looper.size()<<"\n";
for(int A=0;A<looper.size();A++)
{
cout<<looper[A]<<" ";
for(int B=K*A;B<K*(A+1);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);
int dif;
while(true)
{
if(st.size()<K)
return cout<<-1,0;
dif=0;
it_1=st.begin();
while(it_1!=st.end())
{
dif=(-st.begin()->first)-(-it_1->first);
if(dif)
break;
++it_1;
}
if(!dif)
{
/*for(auto A:st)
cout<<-A.first<<"\n";
cout<<"\n";*/
print_1();
break;
}
looper.pb(dif);
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+=dif;
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:24:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int A=0;A<st.size()/K;A++)
~^~~~~~~~~~~~
nicegift.cpp:32:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int A=0;A<looper.size();A++)
~^~~~~~~~~~~~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:60: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 |
380 KB |
n=3 |
3 |
Correct |
3 ms |
584 KB |
n=3 |
4 |
Correct |
2 ms |
584 KB |
n=4 |
5 |
Correct |
2 ms |
584 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
3 ms |
584 KB |
n=3 |
4 |
Correct |
2 ms |
584 KB |
n=4 |
5 |
Correct |
2 ms |
584 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
7 |
Correct |
2 ms |
644 KB |
n=5 |
8 |
Execution timed out |
2059 ms |
314412 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
3 ms |
584 KB |
n=3 |
4 |
Correct |
2 ms |
584 KB |
n=4 |
5 |
Correct |
2 ms |
584 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
7 |
Correct |
2 ms |
644 KB |
n=5 |
8 |
Execution timed out |
2059 ms |
314412 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
918 ms |
314412 KB |
n=1000000 |
2 |
Correct |
585 ms |
314412 KB |
n=666666 |
3 |
Correct |
326 ms |
314412 KB |
n=400000 |
4 |
Runtime error |
203 ms |
314412 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
3 ms |
584 KB |
n=3 |
4 |
Correct |
2 ms |
584 KB |
n=4 |
5 |
Correct |
2 ms |
584 KB |
n=4 |
6 |
Correct |
2 ms |
644 KB |
n=2 |
7 |
Correct |
2 ms |
644 KB |
n=5 |
8 |
Execution timed out |
2059 ms |
314412 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |