题意:100天写程序,给出第n天没有提交,给出m张补题卡,问最多连续提交多少天
思路:首先分两种情况,当补题卡的数目大于没有提交的天数时,连续的就是100天,用数组a存的第几天没提交,注意a[0]和a[n+1],减的时候因为这两个地方卡了很久
/*************************************************************************
> Author: violet0908
> Mail: 605654408@qq.com
> Created Time: 2015年07月22日 星期三
************************************************************************/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while(T--){
int ans, n, m, a[110];
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
ans = 0;
a[0] = 0;
a[n+1] = 101;
if(m>=n){ //补卡数大于缺课数则输出100天
ans = 100;
}
for(int i = 0; i < n; i++){
if(i+m > n) break;
int b = a[i+m+1]-a[i]-1;
if(b > ans)
ans = b;
}
printf("%d\n", ans);
}
return 0;
}