#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,k,a[2000005],s,las,p,cur,maxi,l,r,mid,can;
set<pair<ll,ll> >st;
vector<vector<ll> >ans;
vector<ll>g;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cout.tie(0);
bool ok = 1;
for(int i=1; i<=n; i++){
cin>>a[i];
if(a[i] != a[1])ok = 0;
s += a[i];
st.insert(mp(-a[i] , i));
}
if(s % k){
cout << "-1";
return 0;
}
ll raod = s / k;
ll sum = s;
ll ra = 0;
while(sum){
if((int)st.size() < k){
cout << "-1";
return 0;
}
p = 0,cur = 0;
g.clear();
maxi = -(*st.begin()).f;
for(set<pair<ll,ll> >::iterator it = st.begin(); it != st.end(); it++){
p++;
if(p > k){
cur = (*it).s;
break;
}
las = (*it).s;
}
l = 1 , r = a[las] , mid , can = 1;
while(r >= l){
mid = (l + r) / 2;
if(max(maxi - mid , a[cur]) * k <= sum - mid * k){
l = mid + 1;
can = mid;
}
else {
r = mid - 1;
}
}
sum -= can * k;
ra += k;
p = 0;
g.pb(can);
for(set<pair<ll,ll> >::iterator it = st.begin(); it != st.end(); it++){
p++;
if(p > k){
cur = (*it).s;
break;
}
g.pb((*it).s);
}
for(int i=1; i<g.size(); i++){
st.erase(mp(-a[g[i]] , g[i]));
a[g[i]]-=can;
if(a[g[i]])st.insert(mp(-a[g[i]] , g[i]));
}
ans.pb(g);
}
cout<<ans.size()<<"\n";
for(int i=0; i<ans.size(); i++){
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
cout<<'\n'; }
return 0;
}
Compilation message
nicegift.cpp:13:2: error: stray '\302' in program
ios::sync_with_stdio(0);cin.tie(0);
^
nicegift.cpp:13:3: error: stray '\240' in program
ios::sync_with_stdio(0);cin.tie(0);
^
nicegift.cpp:13:5: error: stray '\302' in program
ios::sync_with_stdio(0);cin.tie(0);
^
nicegift.cpp:13:6: error: stray '\240' in program
ios::sync_with_stdio(0);cin.tie(0);
^
nicegift.cpp:14:2: error: stray '\302' in program
cout.tie(0);
^
nicegift.cpp:14:3: error: stray '\240' in program
cout.tie(0);
^
nicegift.cpp:15:2: error: stray '\302' in program
bool ok = 1;
^
nicegift.cpp:15:3: error: stray '\240' in program
bool ok = 1;
^
nicegift.cpp:15:5: error: stray '\302' in program
bool ok = 1;
^
nicegift.cpp:15:6: error: stray '\240' in program
bool ok = 1;
^
nicegift.cpp:17:2: error: stray '\302' in program
cin>>a[i];
^
nicegift.cpp:17:3: error: stray '\240' in program
cin>>a[i];
^
nicegift.cpp:17:5: error: stray '\302' in program
cin>>a[i];
^
nicegift.cpp:17:6: error: stray '\240' in program
cin>>a[i];
^
nicegift.cpp:17:8: error: stray '\302' in program
cin>>a[i];
^
nicegift.cpp:17:9: error: stray '\240' in program
cin>>a[i];
^
nicegift.cpp:17:11: error: stray '\302' in program
cin>>a[i];
^
nicegift.cpp:17:12: error: stray '\240' in program
cin>>a[i];
^
nicegift.cpp:18:2: error: stray '\302' in program
if(a[i] != a[1])ok = 0;
^
nicegift.cpp:18:3: error: stray '\240' in program
if(a[i] != a[1])ok = 0;
^
nicegift.cpp:18:5: error: stray '\302' in program
if(a[i] != a[1])ok = 0;
^
nicegift.cpp:18:6: error: stray '\240' in program
if(a[i] != a[1])ok = 0;
^
nicegift.cpp:18:8: error: stray '\302' in program
if(a[i] != a[1])ok = 0;
^
nicegift.cpp:18:9: error: stray '\240' in program
if(a[i] != a[1])ok = 0;
^
nicegift.cpp:78:2: error: stray '\302' in program
cout<<ans.size()<<"\n";
^
nicegift.cpp:78:3: error: stray '\240' in program
cout<<ans.size()<<"\n";
^
nicegift.cpp:78:5: error: stray '\302' in program
cout<<ans.size()<<"\n";
^
nicegift.cpp:78:6: error: stray '\240' in program
cout<<ans.size()<<"\n";
^
nicegift.cpp:81:2: error: stray '\302' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:3: error: stray '\240' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:5: error: stray '\302' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:6: error: stray '\240' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:8: error: stray '\302' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:9: error: stray '\240' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:11: error: stray '\302' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:81:12: error: stray '\240' in program
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
^
nicegift.cpp:82:2: error: stray '\302' in program
^
nicegift.cpp:82:3: error: stray '\240' in program
^
nicegift.cpp:82:5: error: stray '\302' in program
^
nicegift.cpp:82:6: error: stray '\240' in program
^
nicegift.cpp:82:8: error: stray '\302' in program
^
nicegift.cpp:82:9: error: stray '\240' in program
^
nicegift.cpp:82:11: error: stray '\302' in program
^
nicegift.cpp:82:12: error: stray '\240' in program
^
nicegift.cpp:82:14: error: stray '\302' in program
^
nicegift.cpp:82:15: error: stray '\240' in program
^
nicegift.cpp:82:17: error: stray '\302' in program
^
nicegift.cpp:82:18: error: stray '\240' in program
^
nicegift.cpp:83:2: error: stray '\302' in program
cout<<'\n'; }
^
nicegift.cpp:83:3: error: stray '\240' in program
cout<<'\n'; }
^
nicegift.cpp:83:5: error: stray '\302' in program
cout<<'\n'; }
^
nicegift.cpp:83:6: error: stray '\240' in program
cout<<'\n'; }
^
nicegift.cpp:83:8: error: stray '\302' in program
cout<<'\n'; }
^
nicegift.cpp:83:9: error: stray '\240' in program
cout<<'\n'; }
^
nicegift.cpp:83:11: error: stray '\302' in program
cout<<'\n'; }
^
nicegift.cpp:83:12: error: stray '\240' in program
cout<<'\n'; }
^
nicegift.cpp: In function 'int main()':
nicegift.cpp:47:42: warning: right operand of comma operator has no effect [-Wunused-value]
l = 1 , r = a[las] , mid , can = 1;
^
nicegift.cpp:70:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<g.size(); i++){
~^~~~~~~~~
nicegift.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<ans.size(); i++){
~^~~~~~~~~~~
nicegift.cpp:81:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<ans[i].size(); j++)cout<<ans[i][j]<<" ";
~^~~~~~~~~~~~~~
nicegift.cpp:28:8: warning: unused variable 'raod' [-Wunused-variable]
ll raod = s / k;
^~~~