1 solutions

  • 0
    @ 2023-12-16 19:51:48

    一开始并非从大到小 需要先选择l和r,再进行sort排序

    #include <iostream>
    #include <bits/stdc++.h>
    using namespace std;
    struct number{
    	int l;
    	int r;
    	int K;
    	int b[10005];
    	int ret;
    }pp[10005];
    int main()
    {
    	int n;
    	int a[1005];
    	cin >> n;
    	for(int i = 1 ;i <= n ;i++){
    		cin >> a[i];
    	}
        int m;
    	cin >> m;
    	for(int i = 1 ;i <= m ;i++){
    		cin >> pp[i].l >>pp[i].r >> pp[i].K;
    		int k = 0;
    		for(int j = pp[i].l ;j <= pp[i].r ;j++){
    			k++;
    			pp[i].b[k] = a[j]; 
    		}
    		sort(pp[i].b + 1 ,pp[i].b + 1 + k);
    		pp[i].ret = pp[i].b[k+1-pp[i].K];
    	}
    	for(int i = 1 ;i <= m ;i++){
    		cout << pp[i].ret << "\n";
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    1799
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    8
    Tags
    # Submissions
    18
    Accepted
    5
    Uploaded By