# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
957092 | Darren0724 | Gift (IZhO18_nicegift) | C++17 | 2039 ms | 157308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
//#define endl '\n'
const int N=200005;
const int INF=1e18;
const int mod=1e9+7;
int32_t main() {
LCBorz;
int n,k;cin>>n>>k;
vector<int> v(n+1);
priority_queue<pair<int,int>> pq;
int total=0;
for(int i=1;i<=n;i++){
cin>>v[i];
pq.push({v[i],i});
total+=v[i];
}
vector<vector<int>> ans;
while(pq.size()>=k){
int mn=0;
vector<int> t;
for(int i=0;i<k;i++){
auto [a,b]=pq.top();
pq.pop();
mn=a;
t.push_back(b);
}
int cost=max((int)1,mn-(k+1));
for(int j:t){
v[j]-=cost;
if(v[j])pq.push({v[j],j});
}
t.push_back(cost);
reverse(all(t));
ans.push_back(t);
}
if(pq.size()!=0){
cout<<-1<<endl;
return 0;
}
cout<<ans.size()<<endl;
for(auto v:ans){
for(int j:v){
cout<<j<<' ';
}
cout<<endl;
}
return 0;
}
Compilation message (stderr)
# | 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... |