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