Pagini recente » Cod sursa (job #2741929) | Cod sursa (job #1419249) | Cod sursa (job #2982941) | Cod sursa (job #2823494) | Cod sursa (job #465675)
Cod sursa(job #465675)
#include<cstdio>
#include<algorithm>
#define eps 10e-6
using namespace std;
int v[100002];
float a[100002];
int cmp (int x,int y)
{
return x>y;
}
int batut (float sum,float rec)
{
if (rec>=sum && rec-sum>=eps) return 1;
return 0;
}
int main ()
{
int n,i,aux,j,rez,poz,cont=0;
float A,B,rec,sum,dif_max;
freopen("minim2.in","r",stdin);
freopen("minim2.out","w",stdout);
scanf("%d",&n);
sum=0;
for (i=1; i<=n; i++)
{
scanf("%f",&a[i]);
sum+=a[i];
}
scanf("%f %f",&A,&B);
scanf("%f",&rec);
sort(a+1,a+n+1,cmp);
while (!batut(sum,rec))
{
if (v[1]==0)
{
v[1]=1;
sum-=a[1]*(1-A);
cont++;
a[1]=a[1]*(1-A);
}
else
{
dif_max=a[1]*(1-B);
rez=1;
poz=2;
while (v[poz]==1 && poz<n)
{
if (a[poz]*(1-B)>dif_max) { dif_max=a[poz]*(1-B); rez=poz; }
poz++;
}
if (a[poz]*(1-A)>dif_max && v[poz]==0) { rez=poz; dif_max=a[poz]*(1-A); }
v[rez]=1;
sum-=dif_max;
cont++;
a[rez]-=dif_max;
}
}
printf("%d\n",cont);
return 0;
}