HTML & JS
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define ff first
#define ss second
int mod = 1e9 + 7;
const int inf = 1e15;
using namespace std;

main()
{
    int T; cin>>T;
    while(T--){
    int n, k; cin>>n>>k;
    int a[n+1];
    f(i, 1, k+1) cin>>a[i];
    int vis[n+1]; memset(vis, 0, sizeof(vis));
    f(i, 1, k+1) vis[a[i]] = 1;
    f(i, 1, n+1)
    {
        f(j, 1, n+1)
        {
            if(vis[j] == 0 && j < n && vis[j+1] > 0) vis[j] = vis[j+1] + 1;
            if(vis[j] == 0 && j > 1 && vis[j-1] > 0) vis[j] = vis[j-1] + 1;
        }
    }
    int m = 0;
    f(i, 1, n+1) m = max(m, vis[i]);
    cout<<m<<"\n";
    }    
}

Generated URL:

Output:

4
4
0
0
0
0
Report Bug