每日一题 第九十二期 Codeforces Round 939 (Div. 2)

A. Nene’s Game

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

Nene invented a new game based on an increasing sequence of integers a 1 , a 2 , … , a k a_1, a_2, \ldots, a_k a1,a2,,ak.

In this game, initially n n n players are lined up in a row. In each of the rounds of this game, the following happens:

  • Nene finds the a 1 a_1 a1-th, a 2 a_2 a2-th, … \ldots , a k a_k ak-th players in a row. They are kicked out of the game simultaneously. If the i i i-th player in a row should be kicked out, but there are fewer than i i i players in a row, they are skipped.

Once no one is kicked out of the game in some round, all the players that are still in the game are declared as winners.

For example, consider the game with a = [ 3 , 5 ] a=[3, 5] a=[3,5] and n = 5 n=5 n=5 players. Let the players be named player A, player B, … \ldots , player E in the order they are lined up initially. Then,

  • Before the first round, players are lined up as ABCDE. Nene finds the 3 3 3-rd and the 5 5 5-th players in a row. These are players C and E. They are kicked out in the first round.
  • Now players are lined up as ABD. Nene finds the 3 3 3-rd and the 5 5 5-th players in a row. The 3 3 3-rd player is player D and there is no 5 5 5-th player in a row. Thus, only player D is kicked out in the second round.
  • In the third round, no one is kicked out of the game, so the game ends after this round.
  • Players A and B are declared as the winners.

Nene has not yet decided how many people would join the game initially. Nene gave you q q q integers n 1 , n 2 , … , n q n_1, n_2, \ldots, n_q n1,n2,,nq and you should answer the following question for each 1 ≤ i ≤ q 1 \le i \le q 1iq independently:

  • How many people would be declared as winners if there are n i n_i ni players in the game initially?
    Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 250 1 \le t \le 250 1t250). The description of test cases follows.

The first line case contains two integers k k k and q q q ( 1 ≤ k , q ≤ 100 1 \le k, q \le 100 1k,q100) — the length of the sequence a a a and the number of values n i n_i ni you should solve this problem for.

The second line contains k k k integers a 1 , a 2 , … , a k a_1,a_2,\ldots,a_k a1,a2,,ak (KaTeX parse error: Expected 'EOF', got '&' at position 10: 1\leq a_1&̲lt;a_2<\ldot…) — the sequence a a a.

The third line contains q q q integers n 1 , n 2 , … , n q n_1,n_2,\ldots,n_q n1,n2,,nq ( 1 ≤ n i ≤ 100 1\leq n_i \leq 100 1ni100).

Output

For each test case, output q q q integers: the i i i-th ( 1 ≤ i ≤ q 1\le i \le q 1iq) of them should be the number of players declared as winners if initially n i n_i ni players join the game.

Example
inputCopy
6
2 1
3 5
5
5 3
2 4 6 7 9
1 3 5
5 4
3 4 5 6 7
1 2 3 4
2 3
69 96
1 10 100
1 1
100
50
3 3
10 20 30
1 10 100
outputCopy
2
1 1 1
1 2 2 2
1 10 68
50
1 9 9

Note

The first test case was explained in the statement.

In the second test case, when n = 1 n=1 n=1, the only player stays in the game in the first round. After that, the game ends and the only player is declared as a winner.

AC代码:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=9901;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;

int t;
int k, q;
int a[110];
int main()
{
	cin >> t;
	while(t --){
		cin >> k >> q;
		for(int i = 1; i <= k; i ++)
		{
			cin >> a[i];
		}
		while(q --){
			int x;
			cin >> x;
			if(x < a[1]) cout << x << " ";
			else cout << a[1] - 1 << " ";
		}
		cout << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值