This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define pii pair<int, int>
#define SZ(x) (int)((x).size())
#define ALL(x) x.begin(), x.end()
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 2e6+6;
ll a[maxn];
void GG(){cout<<-1<<endl; exit(0);}
int fr[maxn];
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
ll n,k; cin>>n>>k;
ll sig = 0;
vector<pair<int, pii> > v;
ll now = 0, h = 0;
REP(i,n) {
cin>>a[i]; sig+=a[i];
}
if (sig % k != 0) {
GG();
}
ll gp = sig / k;
REP(i,n){
v.pb({now, {h, i}});
now += a[i];
bug(now, gp, h);
if (now >= gp) {
now -= gp; ++h;
if (now >= gp) GG();
if (now) {
v.pb({0, {h, i}});
}
}
}
int prv = 0;
v.pb({gp, {-1, -1}});
sort(ALL(v));
int fofo = 0;
REP(i,SZ(v)) {
if (v[i].f != prv) ++fofo;
prv = v[i].f;
}
cout<<fofo<<endl;
prv = 0;
for (auto e : v) {
int df = e.f - prv;
if (df) {
cout<<df<<' ';
REP(i,k) {
cout<<fr[i]<<' ';
}
cout<<'\n';
}
if(~e.s.f) {
fr[e.s.f] = e.s.s+1;
}
prv = e.f;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |