Hiho Interview Problems 2 register

Ended

Participants:465

Verdict:Accepted
Submitted:2014-09-14 13:18:01

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
using namespace std;
int main(){
    int T,N,M;
    int a[105];
    a[0]=0;
    cin>>T;
    while(T){
        T--;
        cin>>N>>M;
        for(int i=1;i<=N;i++){
            cin>>a[i];
        }
        a[N+1]=100;
        if(M>=N){
            cout<<100<<endl;
            continue;
        }
        int MAX=0;
        for(int i=M+1;i<=N+1;i++)
            MAX=max(MAX,a[i]-a[i-M-1]-1);
        cout<<MAX<<endl;
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX