This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
/*--------------------------------------------------------------------------------------*/
signed main() { EmiliaMyWife
int n, k;
cin >> n >> k;
vector<ll> arr(n);
ll sum = 0, mx = 0;
for(int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
mx = max(mx, arr[i]);
}
if(sum % k || mx > sum / k)
return cout << "-1\n", 0;
ll len = sum / k;
ll s = 0;
vector<ll> v, owo(n);
for(int i = 0; i < n; i++) {
s += arr[i];
v.push_back(s % len ? s % len : len);
owo[i] = s;
}
vector<pair<ll, vector<int>>> ans;
sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
ll prv = 0;
for(ll x : v) {
vector<int> tmp(k);
for(int i = 0; i < k; i++) {
tmp[i] = lower_bound(owo.begin(), owo.end(), x + len * i) - owo.begin();
}
ans.push_back({x - prv, tmp});
prv = x;
}
cout << ans.size() << '\n';
for(const auto &[x, y] : ans) {
cout << x;
for(auto w : y)
cout << ' ' << w + 1;
cout << '\n';
}
}
# | 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... |