Pagini recente » Cod sursa (job #579230) | Cod sursa (job #1687748) | Cod sursa (job #134045) | Info Oltenia 2018 Proba pe Echipe Clasele 9 - 10 | Cod sursa (job #2496057)
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream cin("butoaie.in");
ofstream cout("butoaie.in");
int n,k,p,q,dif;
const int nmax=100001;
const int mxval=10000001;
int ans, mij;
int v[nmax+1];
//1 - e ok, poate pot gasi mai mic
//0 - nu e ok, prea mic nr de zile
bool vrf()
{
int newx, q, rs;
for(int i=1; i<=n; i++)
{
newx=v[i]-q*mij;
q=newx/dif;
rs=newx%dif;
if(q+rs<=n)
return 1;
else
return 0;
}
}
int main()
{
cin>>n>>k>>p>>q;
int sum=0;
for(int i=1; i<=n; i++)
{cin>>v[i]; sum+=v[i];}
int st=1, dr=mxval, mij;
//p max
//q min
if(p<q)
{
swap(p,q);
k=n-k;
}
dif=p-q;
//caut bin
while(st<=dr)
{
mij=(st+dr)/2;
if(vrf()==1)
{
ans=mij;
dr=mij-1;
}
else
st=mij+1;
}
cout<<st;
return 0;
}