HIHO 1051 Supplemental Submission Card

Supplementary submission card

Time limit: 2000ms
Single point time limit: 1000ms
Memory Limit: 256MB

describe

Little Ho set himself an ambitious goal: to submit a program on hihoCoder every day for 100 consecutive days. 100 days have passed, Xiao Ho checked his submission record and found that he forgot to submit for N days because of fun. So Xiao Ho rubbed hard and resisted Xiao Hi's contemptuous eyes to ask for M "submission cards" from Xiao Hi. Each "submission card" can make up for one day's submission, turning a day without a submission process into a day with a submission process. Xiao Ho wants to know how many days he can make his "maximum continuous submission days" by using these M supplementary submission cards.

enter

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 line contains N integers a1, a2, ... aN (1 <= a1 < a2 < ... < aN <= 100), indicating that Ho did not submit the program on days a1, a2, ... aN.

output

For each set of data, output the maximum number of consecutive submission days by using the supplementary submission card Little Ho.

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  
59
100

#include <stdio.h>  

#include <algorithm> // used max 
using namespace std;  
int main()  
{  
    int T;  
    int day[105]; // used to store the intermittent date 
    scanf("%d",&T);  
    while(T-- )  
    {  
        int n,m;  
        scanf("%d %d",&n,&m); //n: the number of days not submitted, m: the number of supplementary cards 
        for(int i=1;i<=n;i++)  
        scanf ("%d",&day[i]); //Input storage interval date 
        if(m>=n)  
        {  
            printf("100\n");  
            continue;  
        }  
        else
        {
       day[0]=0; //virtual Day 0 
       day[n+1]=100;  
       int result=0;  // save the maximum number of days
       for(int i=0;i<=n+1;i++)  
       {  
           if(i+m+1<=n+1)  
           result=max(result,day[i+m+1]-day[i]);  
           else  
           result=max(result,day[n+1]-day[i]);  
       }  
       printf("%d\n",result-1);  
}
    }  
    return 0;  
}  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938366&siteId=291194637