CF1676F.Longest Strike

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an array aa of length nn and an integer kk, you are tasked to find any two numbers ll and rr (l≤rl \leq r) such that:

  • For each xx (l≤x≤r)(l \leq x \leq r), xx appears in aa at least kk times (i.e. kk or more array elements are equal to xx).
  • The value r−lr-l is maximized.

If no numbers satisfy the conditions, output -1.

For example, if a=[11,11,12,13,13,14,14]a=[11, 11, 12, 13, 13, 14, 14] and k=2k=2, then:

  • for l=12l=12, r=14r=14 the first condition fails because 1212 does not appear at least k=2k=2 times.
  • for l=13l=13, r=14r=14 the first condition holds, because 1313 occurs at least k=2k=2 times in aa and 1414 occurs at least k=2k=2 times in aa.
  • for l=11l=11, r=11r=11 the first condition holds, because 1111 occurs at least k=2k=2 times in aa.

A pair of ll and rr for which the first condition holds and r−lr-l is maximal is l=13l = 13, r=14r = 14.

给定一个长度为 nn 的数组 aa 和一个整数 kk,你需要找出任意两个数 ll 和 rr(满足 l≤rl \leq r),使得:

  • 对每个 xx(满足 l≤x≤rl \leq x \leq r),xx 在数组 aa 中至少出现 kk 次(即数组中至少有 kk 个元素等于 xx);
  • r−lr-l 的值尽可能大。

若不存在满足条件的数,输出 -1。

例如,若 a=[11,11,12,13,13,14,14]a=[11, 11, 12, 13, 13, 14, 14] 且 k=2k=2,则:

  • 当 l=12l=12、r=14r=14 时,第一个条件不成立,因为 1212 在 aa 中未出现至少 k=2k=2 次;
  • 当 l=13l=13、r=14r=14 时,第一个条件成立,因为 1313 在 aa 中至少出现 k=2k=2 次,且 1414 在 aa 中也至少出现 k=2k=2 次;
  • 当 l=11l=11、r=11r=11 时,第一个条件成立,因为 1111 在 aa 中至少出现 k=2k=2 次。

满足第一个条件且使 r−lr-l 最大的一对 ll 和 rr 是 l=13l = 13、r=14r = 14。

输入格式

The first line of the input contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains the integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤k≤n1 \leq k \leq n) — the length of the array aa and the minimum amount of times each number in the range [l,r][l, r] should appear respectively.

Then a single line follows, containing nn integers describing the array aa (1≤ai≤1091 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤k≤n1 \leq k \leq n),分别表示数组 aa 的长度,以及区间 [l,r][l, r] 中每个数至少应出现的次数。

接下来一行包含 nn 个整数,描述数组 aa(1≤ai≤1091 \leq a_i \leq 10^9)。

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

输出格式

For each test case output 22 numbers, ll and rr that satisfy the conditions, or "-1" if no numbers satisfy the conditions.

If multiple answers exist, you can output any.

对于每个测试用例,输出满足条件的两个数 ll 和 rr;若不存在满足条件的数,则输出 “-1”。

若存在多个答案,可输出任意一个。

输入输出样例

  • 输入#1

    4
    7 2
    11 11 12 13 13 14 14
    5 1
    6 3 5 2 1
    6 4
    4 3 4 3 3 4
    14 2
    1 1 2 2 2 3 3 3 3 4 4 4 4 4

    输出#1

    13 14
    1 3
    -1
    1 4

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

首页