Untitled
raw download clone
C
views 19
,
size 1028 b
#include <stdio.h>
#include <string.h>

int Min(int a, int b);
int Max(int a, int b);

int main(void)
{
    int t;
    int n, m, k;
    int ans = 0;

    scanf("%d", &t);
    for (int h = 0;h < t;h++)
    {

        scanf("%d %d %d", &n, &m, &k);
        int ai[5005] = {0};

        if (k > m) k = m - 1;

        for (int i = 1;i <= n;i++)
        {
            scanf("%d", &ai[i]);
        }
        ans = 0;
        // 選頭i個    選尾k - i個

        for (int i = 0;i <= k;i++)
        {
            int temp = 1000000005;
            // j = 0 取尾 m - k - j
            for (int j = 0;j <= m - 1 - k;j++)
            {
                temp = Min((Max(ai[1 + i + j], ai[n - (m - 1 - k - j) - (k - i)])), temp);
            }
            ans = Max(ans, temp);
        }
        printf("%d\n", ans);
    }
    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 b;
    else return a;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.