Pagini recente » Cod sursa (job #834944) | Cod sursa (job #593983) | Cod sursa (job #1430928) | Cod sursa (job #845414) | Cod sursa (job #253731)
Cod sursa(job #253731)
#include<stdio.h>
#define N 100001
int c[N],pmax,n,m,sus;
void cit_in()
{
int cmax=0;
scanf("%d%d",&n,&m);
for( int i=0 ; i<n ; ++i )
{
scanf("%d",&c[i]);
sus+=c[i];
if(c[i]>cmax)
{
pmax=i;
cmax=c[i];
}
}
}
bool bun(int cx)
{
int sum=0;
for( int i=0 ; i<n ; ++i )
{
if(i!=pmax)
sum+=c[i];
if(sum>cx)
sum-=cx;
}
if(cx-sum+cx<=c[pmax])
return 0;
return 1;
}
long long max(int x)
{
int maxx=0;
for( int cx=sus ; cx ; --cx )
if(bun(cx)==true)
{
for( ; cx%x ; --cx )
if(cx>maxx)
maxx=cx;
}
return maxx;
}
void calc()
{
int x;
for( ; m-- ; printf("\n") )
{
scanf("%d",&x);
printf("%lld",max(x));
}
}
int main()
{
freopen("caramizi.in","r",stdin);
freopen("caramizi.out","w",stdout);
cit_in();
calc();
return 0;
}