12661 - The night's watch
raw download clone
C
views 25
,
size 962 b
#include <stdio.h>

int max(int a, int b);
int min(int a, int b);

int main(void)
{
    int t, n, m, k, ans1, ans2;
    int a[5000];

    scanf("%d", &t);
    for(int i=1; i<=t; i++)
    {
        scanf("%d%d%d", &n, &m, &k);
        for(int j=1; j<=n; j++)
            scanf("%d", &a[j]);
        if(k >= m)
            k = m - 1;
        for(int j=0; j<=k; j++)
        {
            for(int l=0; l<=m-k-1; l++)
            {
                if(l == 0)
                    ans1 = max(a[1+j+l], a[n+j-m+1+l]);
                ans1 = min(ans1, max(a[1+j+l], a[n+j-m+1+l]));
            }
            if(j == 0)
                ans2 = ans1;
            ans2 = max(ans2, ans1);
        }
        printf("%d\n", ans2);
    }

    return 0;
}

int max(int a, int b)
{
    if(a > b)
        return a;
    else
        return b;
}

int min(int a, int b)
{
    if(a < b)
        return a;
    else
        return b;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.