//я так много думал, что опять попал
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1
#define ub upper_bound
#define lb lower_bound
using namespace std;
typedef long long ll;
//17 SEVENTEEN
const long double Pi = acos(-1.0);
const ll dx[] = {0,0,1,-1};
const ll dy[] = {1,-1,0,0};
const ll N = (ll) 1e6 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (ll) 1e14 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }
ll zxc = 1, a[N];
vector<ll> pos;
vector<pair<ll, ll> > v;
vector<pair<ll, vector<ll> > > ans;
bool check() {
for(auto x : v)
if(x.f) return 1;
return 0;
}
void solve() {
ll n, k, mx = 0, sum = 0;
cin >> n >> k;
for(ll i = 1; i <= n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
sum += a[i];
}
if(sum % k) { cout << "-1\n"; return; }
sum /= k;
if(mx > sum) { cout << "-1\n"; return; }
ll cur = 0;
pos.pb(0);
for(ll i = 1; i <= n; i++) {
if(cur + a[i] > sum)
v.pb({sum - cur, i}), a[i] = a[i] - sum + cur, pos.pb(v.size()), i--, cur = 0;
else {
v.pb({a[i], i}), cur += a[i];
if(cur == sum && i != n)
pos.pb(v.size()), cur = 0;
}
}
while(check()) {
vector<ll> cur;
ll mn = inf;
for(ll p : pos) {
mn = min(mn, v[p].f);
cur.pb(v[p].s);
}
ans.pb({mn, cur});
for(ll i = 0; i < pos.size(); i++) {
v[pos[i]].f -= mn;
if(!v[pos[i]].f) pos[i]++;
}
}
cout << ans.size() << "\n";
for(auto x : ans) {
cout << x.f << " ";
for(ll val : x.s) cout << val << " ";
cout << "\n";
}
}
int main(/*Уверенно*/) {
//ios_base::sync_with_stdio(0);
// cin.tie(0);
/*
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
*/
// cin >> zxc;
while(zxc--) {
solve();
}
return 0;
}
// さよならさ いかなくちゃ
Compilation message
nicegift.cpp: In function 'void solve()':
nicegift.cpp:80:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(ll i = 0; i < pos.size(); i++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
0 ms |
204 KB |
n=11 |
11 |
Correct |
379 ms |
4720 KB |
n=50000 |
12 |
Correct |
261 ms |
4588 KB |
n=50000 |
13 |
Correct |
0 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
0 ms |
204 KB |
n=11 |
11 |
Correct |
379 ms |
4720 KB |
n=50000 |
12 |
Correct |
261 ms |
4588 KB |
n=50000 |
13 |
Correct |
0 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
17 |
Correct |
1 ms |
332 KB |
n=989 |
18 |
Correct |
1 ms |
332 KB |
n=563 |
19 |
Correct |
2 ms |
456 KB |
n=592 |
20 |
Correct |
2 ms |
460 KB |
n=938 |
21 |
Correct |
1 ms |
332 KB |
n=747 |
22 |
Correct |
3 ms |
460 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2067 ms |
30448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
0 ms |
204 KB |
n=11 |
11 |
Correct |
379 ms |
4720 KB |
n=50000 |
12 |
Correct |
261 ms |
4588 KB |
n=50000 |
13 |
Correct |
0 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
17 |
Correct |
1 ms |
332 KB |
n=989 |
18 |
Correct |
1 ms |
332 KB |
n=563 |
19 |
Correct |
2 ms |
456 KB |
n=592 |
20 |
Correct |
2 ms |
460 KB |
n=938 |
21 |
Correct |
1 ms |
332 KB |
n=747 |
22 |
Correct |
3 ms |
460 KB |
n=991 |
23 |
Execution timed out |
2067 ms |
30448 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |