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;
#include "books.h"
/*int vo[100005];
int skim(int i)
{
return vo[i];
}
void answer(vector<int>vectorus)
{
int i;
for(i=1;i<vectorus.size();i++)
{
cout<<vectorus[i]<<" ";
}
}
void impossible()
{
cout<<"imp";
}*/
void solve(int N,int K,long long A,int S)
{
long long i,n,k,val,sol,j,a;
n=N;
k=K;
a=A;
vector<int>vec;
// vec.push_back(0);
long long v[100005],suma=0,st,dr,mij;
for(i=1;i<=k-1;i++)
{
v[i]=skim(i);
suma=suma+v[i];
}
if(suma>=A)
{
v[k]=skim(k);
suma=suma+v[k];
if(suma>a*2)
{
impossible();
}
else
{
for(i=1;i<=k;i++)
{
vec.push_back(i);
}
answer(vec);
}
return;
}
else
{
st=k;
dr=n;
sol=0;
while(st<=dr)
{
mij=(st+dr)/2;
val=skim(mij);
if(val+suma<=2*a && val+suma>=a)
{
for(i=1;i<k;i++)
{
vec.push_back(i);
}
vec.push_back(mij);
answer(vec);
return;
}
else if(val+suma<a)
{
st=mij+1;
sol=mij;
}
else
{
dr=mij-1;
}
}
val=skim(k);
v[k]=val;
suma=suma+val;
if(suma>=a && suma<=2*a)
{
for(i=1;i<=k;i++)
{
vec.push_back(i);
}
answer(vec);
return;
}
for(i=1;i<=k;i++)
{
if(i>=sol)
{
impossible();
return;
}
suma=suma-v[i];
suma=suma+skim(sol-i+1);
if(suma>=a && suma<=2*a)
{
for(j=i+1;j<=k;j++)
{
vec.push_back(j);
}
for(j=1;j<=i;j++)
{
vec.push_back(sol-j+1);
}
answer(vec);
return;
}
}
impossible();
return;
}
}
/*int main()
{
int n,i,j,k,l,suma,o;
cin>>n>>k>>suma>>o;
for(i=1;i<=n;i++)
{
cin>>vo[i];
}
solve(n,k,suma,o);
}*/
# | 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... |