#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
typedef double ldouble;
typedef long long llong;
const int maxN = 100001;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
vector<llong> arr(n);
multiset<pair<llong, int>> a;
llong mx = -1, sum = 0;
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
sum += arr[i];
mx = max(mx, arr[i]);
a.insert({arr[i], i});
}
if (sum % k || mx > sum / k)
{
cout << -1 << endl;
exit(0);
}
vector<pair<llong, vector<int>>> ans;
while (a.rbegin()->first)
{
vector<int> cur;
llong mn = a.rbegin()->first;
for (auto it = a.rbegin(); cur.size() < k; ++it)
{
cur.push_back(it->second);
mn = min(mn, it->first);
}
mn = 1;
/*
if (!mn)
{
cout << -1 << endl;
exit(0);
}
*/
for (int x: cur)
{
a.erase({arr[x], x});
a.insert({arr[x] -= mn, x});
}
ans.push_back({mn, cur});
/*cerr << "a` ";
for (pair<llong, int> i: a)
cerr << i.first << ' ';
cerr << endl;*/
}
cout << ans.size() << '\n';
for (auto x: ans)
{
cout << x.first << ' ';
for (int y: x.second)
cout << y + 1 << ' ';
cout << '\n';
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:40:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (auto it = a.rbegin(); cur.size() < k; ++it)
~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
372 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
12 ms |
1396 KB |
n=14 |
10 |
Correct |
8 ms |
1144 KB |
n=11 |
11 |
Correct |
84 ms |
7912 KB |
n=50000 |
12 |
Correct |
82 ms |
7876 KB |
n=50000 |
13 |
Correct |
42 ms |
3980 KB |
n=10 |
14 |
Correct |
38 ms |
3436 KB |
n=685 |
15 |
Correct |
42 ms |
3816 KB |
n=623 |
16 |
Correct |
24 ms |
2280 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
372 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
12 ms |
1396 KB |
n=14 |
10 |
Correct |
8 ms |
1144 KB |
n=11 |
11 |
Correct |
84 ms |
7912 KB |
n=50000 |
12 |
Correct |
82 ms |
7876 KB |
n=50000 |
13 |
Correct |
42 ms |
3980 KB |
n=10 |
14 |
Correct |
38 ms |
3436 KB |
n=685 |
15 |
Correct |
42 ms |
3816 KB |
n=623 |
16 |
Correct |
24 ms |
2280 KB |
n=973 |
17 |
Correct |
41 ms |
2960 KB |
n=989 |
18 |
Correct |
19 ms |
1140 KB |
n=563 |
19 |
Correct |
30 ms |
1396 KB |
n=592 |
20 |
Correct |
32 ms |
1524 KB |
n=938 |
21 |
Correct |
25 ms |
1268 KB |
n=747 |
22 |
Correct |
27 ms |
1396 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2054 ms |
128652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
372 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
12 ms |
1396 KB |
n=14 |
10 |
Correct |
8 ms |
1144 KB |
n=11 |
11 |
Correct |
84 ms |
7912 KB |
n=50000 |
12 |
Correct |
82 ms |
7876 KB |
n=50000 |
13 |
Correct |
42 ms |
3980 KB |
n=10 |
14 |
Correct |
38 ms |
3436 KB |
n=685 |
15 |
Correct |
42 ms |
3816 KB |
n=623 |
16 |
Correct |
24 ms |
2280 KB |
n=973 |
17 |
Correct |
41 ms |
2960 KB |
n=989 |
18 |
Correct |
19 ms |
1140 KB |
n=563 |
19 |
Correct |
30 ms |
1396 KB |
n=592 |
20 |
Correct |
32 ms |
1524 KB |
n=938 |
21 |
Correct |
25 ms |
1268 KB |
n=747 |
22 |
Correct |
27 ms |
1396 KB |
n=991 |
23 |
Execution timed out |
2054 ms |
128652 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |