QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#848401#9989. Harmful Machine LearningQOJQOJQOJWA 27ms3816kbC++141.1kb2025-01-08 20:17:292025-01-08 20:17:31

Judging History

你现在查看的是最新测评结果

  • [2025-01-08 20:17:31]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3816kb
  • [2025-01-08 20:17:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        long long n, x;
        cin >> n >> x;
        vector<long long> a(n);
        for(auto &num: a) cin >> num;
        // Find min_val and its first occurrence
        long long min_val = a[0];
        int min_idx = 0;
        for(int i=1;i<n;i++){
            if(a[i] < min_val){
                min_val = a[i];
                min_idx = i;
            }
        }
        // Swap a[x-1] with a[min_idx] if needed
        if(min_idx != (int)(x-1)){
            swap(a[x-1], a[min_idx]);
        }
        // Collect y = x-1, x, x+1
        // Note: 1-based indexing
        vector<long long> candidates;
        if(x-2 >=0) candidates.push_back(a[x-2]);
        candidates.push_back(a[x-1]);
        if(x < n) candidates.push_back(a[x]);
        // Find the maximum among candidates
        long long ans = *max_element(candidates.begin(), candidates.end());
        cout << ans << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

4
3 2
1 2 3
13 4
1 1 4 5 1 4 1 9 1 9 8 1 0
4 2
1 10 100 1000
1 1
114514

output:

3
4
100
114514

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 3816kb

input:

100000
1 1
1
5 4
1 0 0 0 0
5 4
0 1 1 0 1
2 2
1 1
1 1
1
4 3
0 0 0 1
1 1
0
2 1
1 0
2 2
0 1
3 3
0 0 1
3 1
1 0 0
1 1
1
2 1
0 1
5 4
0 1 1 1 1
1 1
1
5 5
0 0 0 1 0
2 1
1 0
4 4
1 0 0 1
3 2
0 0 1
5 3
1 1 1 0 1
3 3
0 0 1
2 2
1 1
4 1
1 1 0 1
4 1
0 0 1 1
1 1
0
5 4
1 0 1 0 0
4 3
0 0 1 1
1 1
1
3 3
0 1 1
5 4
1 0 0...

output:

1
0
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
0
1
1
0
1
1
0
0
1
1
1
1
1
0
1
1
1
0
1
0
1
1
0
1
1
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
0
1
1
1
1
0
1
1
1
0
0
1
1
1
1
1
1
1
1
0
1
1
0
0
0
1
1
1
1
1
1
1
1
0
0
0
1
1
1
1
1
0
1
1
1
0
1
1
1
0
1
0
1
0
0
1
1
1
1
1
1
1
1
0
1
0
0
1
0
0
1
1
0
1
1
1
1
...

result:

wrong answer 6th lines differ - expected: '0', found: '1'