12661 - The night's watch
raw download clone
CPP
views 7
,
size 1145 b
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

int main() {
    int t, n, m, k;

    cin >> t;
    while (t-- > 0) {
        cin >> n >> m >> k;
        vector<int> abi(n, 0);
        for (int i=0; i<n; i++) {
            cin >> abi[i];
        }

        if (k >= m) {  //只需在意排在我前面的人
            k = m - 1;
        }

        int ans = 0;
        int x;  //暫存
        for (int i=0; i<=k; i++) {  //窮舉可控制的k個人
            int tmp = INT_MAX;
            for (int j=0; j<m-k; j++) {  //窮舉不可控制的人
                if (abi[i+j] >= abi[i+j+n-m]) {  //比較頭尾的大小,x存入較大數字
                    x = abi[i+j];
                } else {
                    x = abi[i+j+n-m];
                }

                if (tmp >= x) {  //窮舉不可控制的人時取較小值
                    tmp = x;
                }
            }

            if (ans <= tmp) {  //窮舉k(可控制)時取較大值
                ans = tmp;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.