Jzoj 1725. MATH (Math.pas/cpp)

Source: Internet
Author: User

1725. "10.6NOIP Universal Simulation" MATH (Math.pas/cpp)
(File IO):input: math.in output: math.out Time limit:ms Space limit: 256000 KB Specific Restrictions Goto Problemset topic Description Little X is doing his maths homework, but the homework is too difficult. The topic is this:

1. Given an n number of series V.

2. You can remove the number of k from the sequence and define the post-removal column as V '.

3. Define m as the maximum of the difference between any two numbers in V ', and M is the minimum value of the difference of any two number in V '.

4. Please choose to delete the number of K, making m+m the smallest.

Little X's maths is so bad that he can only turn to you for help. Enter the first line of two integers n and K.

The second row n integer vi. outputs an integer of one line for the smallest m+m and. Sample Input
5 2

-3-2 3 8 6
Sample Output
7
data range limit for 60% data: 3≤n≤2 000

For 100% of data:

3≤n≤200 000

1≤k≤n-2

-5 000 000≤vi≤5 hint "Sample explanation"

Delete-3 and-2 to get V ' ={3,6,8},m=5,m=2,m+m=7.

This question can be reversed to think:

Because to delete the number of K, then the number of n-k will be left, so we just need to enumerate the number of n-k;

After the qsort is finished,

It can be found that this number of n-k only after the completion of the sequence to make m as minimal as possible, so the enumeration interval, first enumeration start point, the introduction of the end point, the search for the smallest n, looking for if the first to find the smallest n before the start point, re-find, Otherwise, you can update the N and (the difference between the new end point and the last end point) directly and calculate the ANS

{by @bobble! 2017-1-19} ProgramMath;Constinf='math.in'; Outf='Math.out';varN,k,i,min,ans,sp,ep,mp:longint; A,c:Array[1..200000] ofLongint;procedureqsort (l,r:longint);varI,j,x,y:longint;beginI:=l;  J:=r; x:=a[(L+r)Div 2]; Repeat      whileA[i]<x DoInc (I);  whileX&LT;A[J] DoDec (j); if  not(I&GT;J) Then     beginy:=a[i];   A[I]:=A[J]; a[j]:=y;    Inc (I); J:=j-1; End; untilI>J; ifL<j Thenqsort (L,J); ifI<r Thenqsort (i,r);End;beginassign (Input,inf);  Assign (OUTPUT,OUTF); Reset (input);  Rewrite (output);  READLN (N,K);  fori:=1  toN Doread (a[i]); Qsort (1, N);  fori:=1  toN-1  DoC[i]:=a[i+1]-A[i]; MP:=0; Ans:=Maxlongint;  forsp:=1  toN-(N-k) +1   Dosp=Start_point; beginEP:=sp+n-k-1;//End_pointifMp<sp Then        beginmin:=Maxlongint;  fori:= SP toep-1  Do            ifC[i]<min Then             beginmin:=c[i];//min=Min_cha MP:=i; mp=Min_piont              End; End       Else ifc[ep-1]&LT;C[MP] Thenmp:=ep-1; ifANS&GT;A[EP]-A[SP]+C[MP] ThenANS:=A[EP]-A[SP]+C[MP];
c[ep]-c[sp]=max!! End; Writeln (ANS); Close (input); Close (output);End.

Jzoj 1725. MATH (Math.pas/cpp)

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.