Help me in solving CUTOFF problem

My issue

How should i approach to write a code for these problem I have been stuck in these .

Please Help me out apart from the code that I have been written

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t ;
	 cin>>t ;
	 while(t--){
	     int n ,x ;
	     cin>>n>>x>>endl ;
	     int A[n] ;
	     for(int i =0 ;i<=n ; i++){
	        cin >>A[i] ;
	     }
	 }
	return 0;
}

Learning course: Sorting using C++
Problem Link: CodeChef: Practical coding for everyone

@shubhammishrao
Plzz refer my code . I have written it in much simpler way and logic.
Hope u will get it.

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,x;
	    cin>>n>>x;
	    int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    reverse(a,a+n);
	    cout<<a[x-1]-1<<endl;
	}
	return 0;
}