POJ 3258 River Hopscotch (two points)

Source: Internet
Author: User

River Hopscotch
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8975 Accepted: 3859

Description

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to R Ock in a river. The excitement takes place in a long, straight river with a rock at the start and another rock at the end, L unit S away from the start (1≤ L ≤1,000,000,000). Along the between the starting and ending rocks, N (0≤ n ≤50,000) more rocks appear Integral distance di from the start (0 < di < L).

To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping O Nly from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.

Farmer John is proud of he cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rock s placed too closely together. He plans to remove several rocks on order to increase the shortest distance a cow would have the to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he had enough resources to remove up to m Rocks (0≤ MN).

FJ wants to know exactly how much he can increase the shortest distance *before* He starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow have to jump after removing the optimal set of m Rocks.

Input

Line 1:three space-separated integers: L, N, and M
Lines 2.. N+1:each line contains a single integer indicating what far some rock was away from the starting rock. No Rocks share the same position.

Output

Line 1: A single integer which is the maximum of the shortest distance A cow have to jump after removing MRocks

Sample Input

25 5 2214112117

Sample Output

4

Hint

Before removing any rocks, the shortest jump is a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and, the shortest required jump was a jump of 4 (from-to-or from-25).

Source

Usaco 2006 December Silver



test instructions: A river, has n meters long, has the M block of stone, need to remove the K block, so that the shortest distance at that time as large as possible, output that shortest distance.

#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h>using namespace Std;int n,m,k;int num[100010];int main () {while (scanf ("%d%d%d", &n,&m,&k)! =        EOF) {num[0] = 0;        Num[m+1] = n;        for (int i=1;i<=m;i++) {scanf ("%d", &num[i]);        } int l = 0;        int r = N;        int mid;        Sort (num,num+m+2);        int sum = 0;            while (l<r) {int ans = 0;            sum = 0;            Mid = (l+r)/2;                    for (int i=1;i<=m+1;i++) {if ((sum+num[i]-num[i-1)) <=mid) {                    Sum + = Num[i]-num[i-1];                ans++;                } else {sum = 0;            }} if (ans<=k) {L = mid + 1;          } else {r = Mid;  }} printf ("%d\n", L); } return 0;}


Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.

POJ 3258 River Hopscotch (two points)

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.