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>
#include "books.h"
using namespace std;
void solve(int N, int K, long long A, int S)
{
vector<int> vis(N+10);
vector<array<long long, 2>> v;
long long sum=0;
for(int l=0; l<K; l++)
{
long long h=skim(l);
sum+=h;
v.push_back({h, l});
}
if(sum>=A&&sum<=2*A)
{
vector<int> ans;
for(auto i: v) ans.push_back(i[1]);
answer(ans);
}
else if(sum>2*A) impossible();
else
{
for(int l=v.size()-1; l>=0; l--)
{
sum-=v[l][0];
vis[v[l][1]]=0;
int s=v[l][1];
int h=v[l][0];
for(int i=12; i>0; i--)
{
int tmp=s+(1<<i);
if(tmp>N) continue;
while(vis[tmp]) tmp++;
if(tmp<N)
{
h=skim(tmp);
if(h<=2*A-sum) s=tmp;
}
}
h=skim(s);
sum+=h;
v[l][0]=h;
v[l][1]=s;
vis[v[l][1]]=1;
}
if(sum>=A&&sum<=2*A)
{
vector<int> ans;
for(auto i: v) ans.push_back(i[1]);
answer(ans);
}
else
{
return impossible();
}
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |