All pastes #277738 Raw Edit

Mine

public text v1 · immutable
·published 2006-12-13 15:09 UTC
rendered paste body
/* The segment below ---- is the one givin WA for sample test case
   5 5
   1 2 4 6 8 
   The full code above gets WA at test 7 
*/

#include<stdio.h>
#define MAX 10001
int arr[MAX];
int N,K;
int count(int mid)
{
	int val = 0,i;
	for(i=0;i<N;i++)
		val += (arr[i]/mid);
	return val;
}
int main()
{
	int lo,hi=0,mid,max=0,i,c;
	scanf("%d %d",&N,&K);
	for(i=0;i<N;i++)
	{
		scanf("%d",&arr[i]);
		if(arr[i]>hi)
			hi = arr[i];
	}
	if(N==1)
	{
		printf("%d\n",arr[0]/K);
		return 0;
	}
	lo = hi/K;
	while(lo<hi)
	{
		mid = (lo+hi)/2;
lab:	c = count(mid);
		/*while(c>K)
		{
		     mid++;
		     c = count(mid);
		} */
		if(c>=K)
		{
			if(mid>max)
				max = mid;
			lo = mid+1;
		}
		if(c==K)
			lo = mid+1;
		else if(c<K)
			hi = mid-1;
		else
		{
			mid++;
			goto lab;
		}
	}
	printf("%d\n",max);
	return 0;
}

----------------------------------

	while(lo<hi)
	{
		mid = (lo+hi)/2;
lab:	c = count(mid);
		/*while(c>K)
		{
		     mid++;
		     c = count(mid);
		} */
		if(c>=K)
		{
			if(mid>max)
				max = mid;
			lo = mid+1;
		}
		//if(c==K)
		//	lo = mid+1;
		else
			//if(c<K)
			hi = mid-1;
		/*else
		{
			mid++;
			goto lab;
		}*/
	}