Two-part Example 2

Source: Internet
Author: User

Time limit:1000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticePOJ 2456

Description

Farmer John had built a new long barn, with N (2 <= n <= 100,000) stalls. The stalls is located along a straight line at positions X1,..., XN (0 <= XI <= 1,000,000,000).

His C (2 <= C <= N) cows don ' t like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting all other, FJ want to assign the cows to the stalls, such that the minimum distance bet Ween any and them is as large as possible. What's the largest minimum distance?

Input

* Line 1:two space-separated integers:n and C

* Lines 2..n+1:line i+1 contains an integer stall location, xi

Output

* Line 1:one integer:the largest minimum distance

Sample Input

5 312849

Sample Output

3

Hint

OUTPUT DETAILS:

FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3.

Huge input data,scanf is recommended.
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <algorithm>5 using namespacestd;6 Const intinf=1e9+7;7 8 intn,m;9 inta[100005];Ten  One BOOLCintd) A { -     intlast=1; -      for(intI=1; i<m;i++) the     { -         intcrt=last+1; -          while(Crt<=n && a[crt]-a[last]<d) -         { +crt++; -         } +         if(crt==n+1) A             return false; atlast=CRT; -     } -     return true; - } -  - intMain () in { -     inti,j; to      while(SCANF ("%d%d", &n,&m)! =EOF) +     { -          for(i=1; i<=n;i++) thescanf"%d",&a[i]); *Sort (A +1, a+n+1); $         intlb=0, ub=INF;Panax Notoginseng          while(ub-lb>1) -         { the             intMid= (LB+UB)/2; +             if(C (mid)) Alb=mid; the             Else +ub=mid; -         } $printf"%d\n", LB); $     } -     return 0; -}
View Code

Two-part Example 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.