Pagini recente » Cod sursa (job #2167898) | Cod sursa (job #1259272) | oni_11_12_0 | Cod sursa (job #490796) | Cod sursa (job #270633)
Cod sursa(job #270633)
#include <stdio.h>
#include <algorithm>
#define GET_BUF fread(b,sizeof(char),8192,stdin)
#define BL 8192
using namespace std;
int n,m,i,j,p,q,a[200005],Q[200005],ind[200005];
int low,high,mid,x;
char b[BL];
long long s[200005],SS;
void read(bool k,int n){
int x;
for (i=1;i<=n;++i){
x=0; if (j==BL){q=GET_BUF;j=0;}
while ( b[j]>='0' && b[j]<='9' && j<q ){
x=x*10+b[j]-'0';
j++;if (j==BL){q=GET_BUF;j=0;}
}
j++;
if (j==BL){q=GET_BUF;j=0;}
if (!k)a[i]=x;else Q[i]=x;
}
}
int main(){
freopen("caramizi.in","r",stdin); freopen("caramizi.out","w",stdout);
scanf("%d %d\n",&n,&m);
q=GET_BUF;
read(0,n);
read(1,m);/*
for (i=1;i<=n;++i)printf("%d ",a[i]);
printf("\n");
for (i=1;i<=m;++i)printf("%d ",Q[i]);*/
sort(a+1,a+n+1);
for (i=1;i<=n;++i)s[i]=s[i-1]+a[i];
p=0;
for (i=1;i<=n;++i)if (a[i]!=a[i+1])ind[++p]=i;
for (j=1;j<=1000000;++j){
low=1;high=p+1;x=j;
while (low<high){
mid=(high+low)>>1;
if (x<=a[ind[mid]])high=mid;
else low=mid+1;
}
if (a[ind[low]]==x)SS=s[ind[low]]+x*(n-ind[low]);
else SS=s[ind[low-1]]+x*(n-ind[low-1]);
//printf("%lld",(SS/x)*x);
}
return 0;
}