Interval k large number find Java Blue Bridge Cup ALGO-1

Source: Internet
Author: User

1 Importjava.util.Arrays;2 ImportJava.util.Scanner;3 4  Public classMain {5      Public Static voidMain (string[] args) {6Scanner Ascanner =NewScanner (system.in);7     intN= Ascanner.nextint ();//read the first one8     LongA[] =New Long[n];//Storing Arrays9     LongB[] =New Long[n];//Alternate ArrayTen      One      for(inti=0;i<n;i++) A     { -A[i] =ascanner.nextint (); -     } the     intm =ascanner.nextint (); -     int[]l =New int[1001]; -     int[]r =New int[1001]; -     int[]k =New int[1001]; +      for(inti=0;i<m;i++) -     { +L[i] =ascanner.nextint (); AR[i] =ascanner.nextint (); atK[i] =ascanner.nextint (); -          for(intj=l[i]-1;j<r[i];j++) -         { -B[J-L[I]+1] =A[j]; -         } - Arrays.sort (b); inSystem.out.println (b[b.length-K[i]]); -Arrays.fill (b, ' + ')); to          +     } -     } the}

The two-dimensional array that was used when it was first started, using the bubbling sort, but involved a three-layer loop, and finally though the results came out, the run timed out.

So the need to optimize the method, and then refer to the online standard answer after a sorting function can use the sort () function, directly using the Arrays.sort () function array of small to large order, each time the results are directly output.

At the same time, I need to clear the results after the loop, I use the Arrays.fill () function, with ' "" to fill, but there are insufficient places, will be emptied after the form of 0 exist, the length of the array has not changed, so need me to further improve, the final evaluation results still have a run timeout!! , for informational purposes only

Interval k large number find Java Blue Bridge Cup ALGO-1

Related Article

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.