工作生活

1617:补提交

2019-07-04  本文已影响0人  Celia_QAQ

Description

TOM给自己定了一个宏伟的目标:连续100天每天坚持在zcmu上提交一个程序。100天过去了,tom查看自己的提交记录发现有N天因为贪玩忘记提交了。于是TOM要来M张"补提交卡"。每张"补提交卡"都可以补回一天的提交,将原本没有提交程序的一天变成有提交程序的一天。tom想知道通过利用这M张补提交卡,可以使自己的"最长连续提交天数"最多变成多少天。

Input

第一行是一个整数T(1 <= T <= 10),代表测试数据的组数。

每个测试数据第一行是2个整数N和M(0 <= N, M <= 100)。第二行包含N个整数,表示第a1, a2, ... aN天TOM没有提交程序。ai<=100

Output

对于每组数据,输出通过使用补提交卡TOM的最长连续提交天数最多变成多少。

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

参考:https://blog.csdn.net/qq_41117236/article/details/81604292

AC代码:一定要记得0和100的值

#include<vector>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=300050;

int main(){
   int t,temp,m,n;
    int a[maxn];a[0]=0;
    scanf("%d",&t);
    while(t--){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    if(n<=m)printf("100\n");

    else {
        int Max=a[m+1];
        
        for(int i=0;i<=n-m;i++)
                Max=max(Max,a[i+m+1]-a[i]);
        Max=max(Max,100-a[n-m]);
        if(Max==100-a[n-m])
            Max=Max;
        else Max--;
        printf("%d\n",Max);
        }  
   }

     return 0;
}
上一篇下一篇

猜你喜欢

热点阅读