Question 1: Time Limit for completing the submission card: Ms single point of time: Ms memory limit: MB description
Mr. Ho has set himself an ambitious goal: to commit a program on hihocoder every day for 100 consecutive days. The first day passed. Xiao ho checked his submission records and found that he had submitted the application for N days. So small ho soft and hard foam, endure the small hi despise eyes from the small hi where to come to M "fill submit card ". Each "makeup card" can be used to make up for one-day submission, changing the day when no program is submitted to another application. Mr. Ho wants to know the maximum number of days for his "Maximum number of consecutive submission Days" by using this m makeup card.
Input
The first line is an integer T (1 <=t <= 10), representing the number of groups of test data.
The first row of each test data is 2 integers n and M (0 <= n, m <= 100 ). The second row contains N integers A1, A2 ,... an (1 <= A1 <A2 <... <An <= 100) indicates the A1, A2 ,... an Tian xiao Ho did not submit the program.
Output
For each group of data, the maximum number of consecutive submission days that can be changed by using the replenishment commit card small Ho is output.
-
Sample Input
-
3 5 1 34 77 82 83 84 5 2 10 30 55 56 90 5 10 10 30 55 56 90
-
Sample output
-
76 59100
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int a[101];int main(){ int t; int n, m; int max; int i, j; scanf("%d", &t); while(t--) { scanf("%d %d", &n, &m); if(n<=m) { for(i=0; i<n; i++) { scanf("%d", &a[i]); } printf("100\n"); continue; } for(i=1; i<=n; i++ ) { scanf("%d", &a[i] ); } a[0]=0; int cnt; max=0; for(j=m+1; j<=n; j++ ) { cnt = a[j]-a[j-m-1]-1 ; if(cnt > max ) max = cnt ; } printf("%d\n", max ); } return 0;}
Hihocoder online testing (Google)