Hiho Interview Problems 2 register

Ended

Participants:465

Verdict:Accepted
Submitted:2014-09-14 14:00:43

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
26
27
28
29
#include <iostream>
using namespace std;
int T,n,m;
int A[143];
int missed[143], S[143];
int main(){
    cin >> T;
    while (T--) {
        cin >> n >> m;
        for (int i = 0; i <= 100; i++) S[i] = missed[i] = 0;
        for (int i = 0; i < n; i++) {
            cin >> A[i];
            missed[A[i]] = 1;
        }
        if (m >= n) {
            cout << 100 << endl;
            continue;
        }
        int Ans = A[m]-1;
        for (int i = 1; i+m < n; i++)
            if (A[i+m]-A[i-1]-1 > Ans)
                Ans = A[i+m]-A[i-1]-1;
        cout << Ans << endl;
            
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX