Rocky P2678 jump stone, rocky p2678 stone
Background
The annual "Stone jumping" competition is about to begin again!
Description
The competition will take place in a straight river, where some huge rocks are distributed. The organizing committee has already selected two rocks as the start and end points of the competition. There are N rocks between the start point and the end point (not including the start point and the end point ). During the competition, contestants will jump from the starting point and each step to the adjacent rock until they reach the final point.
In order to improve the difficulty of the competition, the Organizing Committee planned to remove some rocks so that contestants could jump as long as possible during the competition. Due to budget restrictions, the organizing committee can remove at most M Blocks of rock from the start point and the end point (not the start point and the end point of the rock ).
Input/Output Format
Input Format:
The input file name is stone. in.
The first line of the input file contains three integers, L, N, M, indicating the distance from the start point to the end point, the number of rocks between the start point and the end point, and the maximum number of rocks removed by the organizing committee.
In the next N rows, each row has an integer. The integer Di (0 <Di <L) in the I row indicates the distance between the rock block and the start point. These rocks are given in ascending order from the starting point, and no two rocks appear in the same position.
Output Format:
The output file name is stone. out. The output file contains only one integer, that is, the maximum shortest hop distance.
Input and Output sample input sample #1: Copy
25 5 2 2111417 21
Output example #1: Copy
4
Description
Input and Output Example 1: After removing two rocks 2 and 14 from the start point, the shortest hop distance is 4 (from rock 17 to rock 21 or from rock 21 to the final point ).
For 20% of data, 0 ≤ M ≤ N ≤ 10. For 50% of data, 0 ≤ M ≤ N ≤ 100.
For 100% of data, 0 ≤ M ≤ N ≤ 50,000, 1 ≤ L ≤ 1,000,000,000.
Think about how to write the program at the end of the day,
Native23333 ....
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 const int MAXN=100001; 6 inline int read() 7 { 8 char c=getchar();int x=0,f=1; 9 while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}10 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*f;11 }12 int L,n,m;13 int pos[MAXN];14 bool check(int val)15 {16 int need=0,pre=0;17 for(int i=1;i<=n;i++)18 {19 if(pos[i]-pre<val) need++;20 else pre=pos[i];21 }22 if(need>m) return 0;23 else return 1;24 }25 int main()26 {27 L=read(),n=read(),m=read();28 for(int i=1;i<=n;i++)29 pos[i]=read();30 int l=0,r=L,ans=0;31 while(l<=r)32 {33 int mid=l+r>>1;34 if(check(mid)) ans=mid,l=mid+1;35 else r=mid-1; 36 }37 printf("%d",ans);38 return 0;39 }