Codeforces Problem 1980B Choosing cubes(基本排序)

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;
}

加油

  • 26
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值