#1051: Time limit for filing cards:2000msSingle Point time limit:1000msMemory Limit:256MB
Describe
Little Ho set himself a grand goal: 100 days in a row, insist on submitting a program on Hihocoder every day. 100 days later, Little Ho view their submission records found that there were n days because fun forgot to submit. So little Ho Ruanmoyingpao, to suppress the small hi despise the eyes from the young hi there to M Zhang "fill the card." Each "fill-in card" can be used to back up one day's submission, turning the day without the submission process into a single day of submission. Little Ho wants to know that by using this M-fill submission card, you can make your "longest consecutive commit days" become as many days as possible.
Input
The first line is an integer t (1 <= T <= 10), which represents the number of groups of test data.
The first line of each test data is 2 integers of N and m (0 <= N, M <= 100). The second line contains n integers a1, A2, ... an (1 <= A1 < A2 < ... < an <= 100), indicating that the first A1, A2, ... an day small Ho did not submit the procedure.
Output
For each set of data, the output is the maximum number of consecutive commit days to be made by using the complement submission card for small ho.
-
-
Sample input
-
-
3 5 1 2 5 10 30 55 56 ( 5 90)
-
-
Sample output
-
-
59100
Import Java.util.scanner;public class Main { private static int maxlen (int arr[],int m,int n) { if (m>=n) return ; int res = arr[m]-1; for (int i=0;i+m+1<n;i++) { res = Math.max (res, arr[i+m+1]-arr[i]-1); } res = Math.max (res, 100-arr[n-m-1]); return res; } public static void Main (String args[]) { Scanner sc = new Scanner (system.in);/* Scanner sc = null; try { sc = new Scanner (New FileInputStream ("C:\\users\\ddguo\\desktop\\input.txt")); } catch ( FileNotFoundException e) { //TODO auto-generated catch block e.printstacktrace (); } * /int num = Sc.nextint (); while (num-->0) { int n = sc.nextint (); int m = Sc.nextint (); int arr[] = new Int[n]; for (int i=0;i<n;i++) { arr[i]= sc.nextint (); } System.out.println (MaxLen (arr, M, N)); } Sc.close (); }}
[Hihocoder] #1051: Fill the submission card