# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367616 | nicolaalexandra | Gift (IZhO18_nicegift) | C++14 | 1442 ms | 101328 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>
#define DIM 1000010
using namespace std;
//set <pair<long long,int> > s;
priority_queue <pair<long long,int> > h;
vector <pair<long long,int> > w;
vector <long long> sol[DIM];
long long v[DIM];
int n,k,i,el;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>k;
long long sum = 0;
for (i=1;i<=n;i++){
cin>>v[i];
h.push(make_pair(v[i],i));
sum += v[i];
}
if (sum % k){
cout<<-1;
return 0;
}
long long cnt = sum / k;
while (!h.empty()){
if (h.size() < k){
cout<<-1;
return 0;
}
int pas = 0; long long val = 0, val2 = 0;
w.clear();
for (int i=1;i<=k;i++){
val = h.top().first;
int poz = h.top().second;
h.pop();
w.push_back(make_pair(val,poz));
}
if (!h.empty())
val2 = h.top().first;
val = min (val,cnt - val2);
sol[++el].push_back (val);
cnt -= val;
for (auto it : w){
long long x = it.first; int poz = it.second;
sol[el].push_back(poz);
if (x > val)
h.push(make_pair(x-val,poz));
}
}
cout<<el<<"\n";
for (i=1;i<=el;i++){
for (auto it : sol[i])
cout<<it<<" ";
cout<<"\n";
}
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... |