CF1749C.Number Game

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing a game. They have an array of positive integers aa of size nn.

Before starting the game, Alice chooses an integer k≥0k \ge 0. The game lasts for kk stages, the stages are numbered from 11 to kk. During the ii-th stage, Alice must remove an element from the array that is less than or equal to k−i+1k - i + 1. After that, if the array is not empty, Bob must add k−i+1k - i + 1 to an arbitrary element of the array. Note that both Alice's move and Bob's move are two parts of the same stage of the game. If Alice can't delete an element during some stage, she loses. If the kk-th stage ends and Alice hasn't lost yet, she wins.

Your task is to determine the maximum value of kk such that Alice can win if both players play optimally. Bob plays against Alice, so he tries to make her lose the game, if it's possible.

爱丽丝和鲍勃正在玩一个游戏。他们有一个长度为 nn 的正整数数组 aa。

游戏开始前,爱丽丝选择一个整数 k≥0k \ge 0。游戏共进行 kk 轮,轮次编号从 11 到 kk。在第 ii 轮中,爱丽丝必须从数组中删除一个不大于 k−i+1k - i + 1 的元素;随后,若数组非空,鲍勃必须将 k−i+1k - i + 1 加到数组中任意一个元素上。注意,爱丽丝的操作与鲍勃的操作共同构成同一轮游戏的两个部分。若在某一轮中爱丽丝无法删除满足条件的元素,则她立即输掉游戏;若成功完成第 kk 轮且爱丽丝仍未输,则她获胜。

你的任务是:在双方均采取最优策略的前提下,求出爱丽丝能够获胜的最大 kk 值。鲍勃与爱丽丝对抗,因此只要有可能,他总会尽力使爱丽丝输掉游戏。

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the size of the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n).

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示数组 aa 的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n)。

输出格式

For each test case, print one integer — the maximum value of kk such that Alice can win if both players play optimally.

对于每个测试用例,输出一个整数——即在双方均采取最优策略的情况下,Alice 能获胜的最大 kk 值。

输入输出样例

  • 输入#1

    4
    3
    1 1 2
    4
    4 4 4 4
    1
    1
    5
    1 3 2 1 1

    输出#1

    2
    0
    1
    3

输入解题思路,AI测评打分。不知道怎么写?

首页