이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long s = accumulate(a.begin(), a.end(), 0LL);
if (s % k != 0 || a[0] > s / k) {
cout << -1 << '\n';
return 0;
}
set<pair<long long, int>> st;
for (int i = 0; i < n; i++) {
st.emplace(a[i], i);
}
vector<vector<long long>> res;
while (s > 0) {
vector<int> ids;
for (int foo = 0; foo < k; foo++) {
auto it = prev(st.end());
ids.push_back(it->second);
st.erase(it);
}
long long v = a[ids.back()];
if (!st.empty()) {
v = min(v, s / k - prev(st.end())->first);
}
res.push_back({v});
for (int i : ids) {
res.back().push_back(i + 1);
}
for (int i : ids) {
s -= v;
a[i] -= v;
if (a[i] > 0) {
st.emplace(a[i], i);
}
}
}
cout << (int) res.size() << '\n';
for (int i = 0; i < (int) res.size(); i++) {
for (int j = 0; j < (int) res[i].size(); j++) {
cout << res[i][j] << " ";
}
cout << '\n';
}
return 0;
}
# | 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... |