Menu

SPOJ CURDPROD – CURD PRODUCERS

January 1, 2017 - SPOJ

Language: C++

#include<iostream>
#include<stdio.h>
#include<algorithm>
#define sf scanf
#define pf printf
using namespace std;
long long int findcurd(int a[],int n,long long int temp)
{
	long long int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=(temp/a[i]);
	}
return ans;
}
long long int bs(int a[],int n,int T,long long int high)
{
	long long int low=1,mid;
	while(low<high)
	{
		mid=(low+high)>>1;
		long long int curd=findcurd(a,n,mid);
		if(curd<T)
		low=mid+1;
		else
		high=mid;
	}
return high;
}
int main()
{
	int t;
	sf("%d",&t);
	while(t--)
	{
		int n,k,a[10001]={0};
		long long int ma=-1;
		sf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
		{
			sf("%d",&a[i]);
			ma=max(ma,(long long int)a[i]);
		}
		pf("%lldn",bs(a,n,k,ma*k));
	}
return 0;
}

(92)

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on VK

Author of this post : Anuj Chauhan

Leave a Reply

Your email address will not be published. Required fields are marked *