CF1610E.AmShZ and G.O.A.T.

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's call an array of kk integers c1,c2,…,ckc_1, c_2, \ldots, c_k terrible, if the following condition holds:

  • Let AVGAVG be the c1+c2+…+ckk\frac{c_1 + c_2 + \ldots + c_k}{k}(the average of all the elements of the array, it doesn't have to be integer). Then the number of elements of the array which are bigger than AVGAVG should be strictly larger than the number of elements of the array which are smaller than AVGAVG. Note that elements equal to AVGAVG don't count.

    For example c=1,4,4,5,6c = {1, 4, 4, 5, 6} is terrible because AVG=4.0AVG = 4.0 and 55-th and 44-th elements are greater than AVGAVG and 11-st element is smaller than AVGAVG.

Let's call an array of mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m bad, if at least one of its non-empty subsequences is terrible, and good otherwise.

You are given an array of nn integers a1,a2,…,ana_1, a_2, \ldots, a_n. Find the minimum number of elements that you have to delete from it to obtain a good array.

An array is a subsequence of another array if it can be obtained from it by deletion of several (possibly, zero or all) elements.

我们称一个包含 kk 个整数的数组 c1,c2,…,ckc_1, c_2, \ldots, c_k 是糟糕的(terrible),如果满足以下条件:

  • 设 AVG=c1+c2+…+ckkAVG = \frac{c_1 + c_2 + \ldots + c_k}{k}(即该数组所有元素的平均值,不一定是整数)。那么,数组中严格大于 AVGAVG 的元素个数必须严格大于数组中严格小于 AVGAVG 的元素个数。注意:等于 AVGAVG 的元素不计入比较。

    例如,数组 c={1,4,4,5,6}c = \{1, 4, 4, 5, 6\} 是糟糕的,因为 AVG=4.0AVG = 4.0,其中第 44 和第 55 个元素(即 55 和 66)大于 AVGAVG,而第 11 个元素(即 11)小于 AVGAVG。

我们称一个包含 mm 个整数的数组 b1,b2,…,bmb_1, b_2, \ldots, b_m 是坏的(bad),如果它至少存在一个非空子序列是糟糕的;否则称其为好的(good)。

现给你一个包含 nn 个整数的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。求最少需要从中删除多少个元素,才能使其变为一个好的数组。

若一个数组可通过从另一数组中删除若干(可能为零或全部)元素得到,则称其为该数组的一个子序列。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the size of aa.

The second line of each testcase contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — elements of array aa.

In each testcase for any 1≤i<n1 \le i \lt n it is guaranteed that ai≤ai+1a_i \le a_{i+1}.

It is guaranteed that the sum of nn over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 数组 aa 的元素。

对于每个测试用例,保证对任意 1≤i<n1 \le i \lt n,均有 ai≤ai+1a_i \le a_{i+1}。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print the minimum number of elements that you have to delete from it to obtain a good array.

对于每个测试用例,输出为使数组变为“好数组”所需删除的最少元素个数。

输入输出样例

  • 输入#1

    4
    3
    1 2 3
    5
    1 4 4 5 6
    6
    7 8 197860736 212611869 360417095 837913434
    8
    6 10 56026534 405137099 550504063 784959015 802926648 967281024

    输出#1

    0
    1
    2
    3

说明/提示

In the first sample, the array aa is already good.

In the second sample, it's enough to delete 11, obtaining array [4,4,5,6][4, 4, 5, 6], which is good.

在第一个样例中,数组 aa 已经是“好”的。

在第二个样例中,只需删除 11,得到数组 [4,4,5,6][4, 4, 5, 6],该数组是“好”的。

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

首页