time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Dmitry has n𝑛 cubes, numbered from left to right from 11 to n𝑛. The cube with index f𝑓 is his favorite.
Dmitry threw all the cubes on the table, and the i𝑖-th cube showed the value ai𝑎𝑖 (1≤ai≤100). After that, he arranged the cubes in non-increasing order of their values, from largest to smallest. If two cubes show the same value, they can go in any order.
After sorting, Dmitry removed the first k𝑘 cubes. Then he became interested in whether he removed his favorite cube (note that its position could have changed after sorting).
For example, if 𝑛=5,𝑓=2, 𝑎=[4,3,3,2,3] (the favorite cube is highlighted in green), and k=2, the following could have happened:
- After sorting]𝑎=[4,3,3,3,2], since the favorite cube ended up in the second position, it will be removed.
- After sorting ]𝑎=[4,3,3,3,2], since the favorite cube ended up in the third position, it will not be removed.
Input
The first line contains an integer t𝑡 (1≤t≤1000) — the number of test cases. Then follow the descriptions of the test cases.
The first line of each test case description contains three integers n𝑛, f𝑓, and k𝑘 (1≤f,k≤n≤100) — the number of cubes, the index of Dmitry's favorite cube, and the number of removed cubes, respectively.
The second line of each test case description contains n𝑛 integers ai𝑎𝑖 (1≤ai≤100) — the values shown on the cubes.
Output
For each test case, output one line — "YES" if the cube will be removed in all cases, "NO" if it will not be removed in any case, "MAYBE" if it may be either removed or left.
You can output the answer in any case. For example, the strings "YES", "nO", "mAyBe" will be accepted as answers.
这道题的大概意思就是:给定一个数组,输入三个数n,f,k。f是未排序前最喜欢数的下标(也就是a[f] = x),然后排序数组(大->小),删除前k的数,删除之后是否删掉了x这个数
不确定输出“MAYBE”,确定输出“YES”,没有输出“NO”
模拟题,代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 110;
int t,n,f,k;
int a[MAXN];
bool cmp(int a,int b){
return a > b;
}
int main()
{
memset(a,0,sizeof(a));
cin >> t;
while(t--){
cin >> n >> f >> k;
for(int i = 1;i <= n;i ++){
cin >> a[i];
}
int x = a[f];
sort(a+1,a+n+1,cmp);
int flag = 0;
for(int i = 1;i <= k;i ++){
if(a[i] == x) flag = 1;
a[i] = 0;
}
if(flag == 0) cout << "NO" << endl;
else{
int k = 0;
for(int i = 1; i <= n;i ++){
if(a[i] == 0) continue;
if(a[i] == x) k = 1;
}
if(k) cout << "MAYBE" << endl;
else cout << "YES" << endl;
}
}
return 0;
}
加油