# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84906 | ToadDaveski | Gift (IZhO18_nicegift) | C++14 | 2056 ms | 104264 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 ll long long
#define fr first
#define sc second
using namespace std;
vector <vector <pair <ll,ll> > > q;
ll a[2000001];
map <ll,ll> poz;
vector <ll> ans;
int main()
{
ll n,k,i,j,ma=0;
cin>>n>>k;
ll sum=0,part;
for(i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
ma=max(ma,a[i]);
}
part=sum/k;
if (sum%k || part<ma )
{
cout<<-1;
return 0;
}
sum=0;
vector <pair <ll,ll> > temp;
for(i=1;i<=n;i++)
{
sum+=a[i];
if (sum>=part)
{
temp.push_back({a[i]-(sum-part),i});
q.push_back(temp);
temp.clear();
sum=sum-part;
if (sum) temp.push_back({sum,i});
}
else
{
temp.push_back({a[i],i});
}
}
while(true)
{
ll mi=1e18;
for(i=0;i<k;i++)
mi=min(mi,q[i][poz[i]].fr);
ans.push_back(mi);
ll kol=0;
for(i=0;i<k;i++)
{
ans.push_back(q[i][poz[i]].sc);
q[i][poz[i]].fr-=mi;
if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
{
poz[i]++;
if (poz[i]<q[i].size()) kol++;
}
}
if (!kol)
break;
}
ll toad=0;
cout<<ans.size()/(k+1)<<endl;
while(toad<ans.size())
{
cout<<ans[toad]<<" ";
if (((toad+1)%(k+1))==0)
cout<<endl;
toad++;
}
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... |