#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(); it != a.rend(); ++it)
{
cur.push_back(it->second);
mn = min(mn, it->first);
}
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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1520 ms |
86908 KB |
Not all heaps are empty in the end |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |