#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
ll N, K, A[100006], sum, acc[100006], id[100006];
vector<pair<ll, pll>> v;
vector<ll> t;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++)
{
cin >> A[i];
sum += A[i];
}
if (sum % K)
{
cout << -1 << '\n';
return 0;
}
for (int i = 1; i <= N; i++)
if (A[i] > sum / K)
{
cout << -1 << '\n';
return 0;
}
int cur = 1;
for (int i = 1; i <= N; i++)
{
if (A[i] >= sum / K - acc[cur])
{
v.emplace_back(make_pair(acc[cur], pll(cur, i)));
A[i] -= sum / K - acc[cur];
cur++;
}
if (A[i])
v.emplace_back(make_pair(acc[cur], pll(cur, i)));
acc[cur] += A[i];
}
v.emplace_back(make_pair(sum / K, pll(0, 0)));
for (auto [a, p] : v)
t.emplace_back(a);
sort(v.begin(), v.end());
sort(t.begin(), t.end());
t.resize(unique(t.begin(), t.end()) - t.begin());
cout << t.size() - 1 << '\n';
int vdx = 0;
for (int i = 1; i < t.size(); i++)
{
cout << t[i] - t[i - 1];
while (vdx < v.size() && v[vdx].F <= t[i - 1])
{
id[v[vdx].S.F] = v[vdx].S.S;
vdx++;
}
for (int i = 1; i <= K; i++)
cout << ' ' << id[i];
cout << '\n';
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:47:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for (auto [a, p] : v)
| ^
nicegift.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 1; i < t.size(); i++)
| ~~^~~~~~~~~~
nicegift.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while (vdx < v.size() && v[vdx].F <= t[i - 1])
| ~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
328 KB |
n=4 |
6 |
Correct |
0 ms |
340 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
328 KB |
n=4 |
6 |
Correct |
0 ms |
340 KB |
n=2 |
7 |
Correct |
0 ms |
340 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
340 KB |
n=14 |
10 |
Correct |
0 ms |
340 KB |
n=11 |
11 |
Correct |
21 ms |
3440 KB |
n=50000 |
12 |
Correct |
16 ms |
3384 KB |
n=50000 |
13 |
Correct |
0 ms |
340 KB |
n=10 |
14 |
Correct |
1 ms |
328 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
328 KB |
n=4 |
6 |
Correct |
0 ms |
340 KB |
n=2 |
7 |
Correct |
0 ms |
340 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
340 KB |
n=14 |
10 |
Correct |
0 ms |
340 KB |
n=11 |
11 |
Correct |
21 ms |
3440 KB |
n=50000 |
12 |
Correct |
16 ms |
3384 KB |
n=50000 |
13 |
Correct |
0 ms |
340 KB |
n=10 |
14 |
Correct |
1 ms |
328 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
324 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
2004 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
328 KB |
n=4 |
6 |
Correct |
0 ms |
340 KB |
n=2 |
7 |
Correct |
0 ms |
340 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
340 KB |
n=14 |
10 |
Correct |
0 ms |
340 KB |
n=11 |
11 |
Correct |
21 ms |
3440 KB |
n=50000 |
12 |
Correct |
16 ms |
3384 KB |
n=50000 |
13 |
Correct |
0 ms |
340 KB |
n=10 |
14 |
Correct |
1 ms |
328 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
324 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
23 |
Runtime error |
13 ms |
2004 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |