Codeforces Round 900 (Div. 3)

How Much Does Daytona Cost?

We define an integer to be the most common on a subsegment, if its number of occurrences on that subsegment is larger than the number of occurrences of any other integer in that subsegment. A subsegment of an array is a consecutive segment of elements in the array a.

Given an array a of size n, and an integer k, determine if there exists a non-empty subsegment of a where k is the most common element.

Input

Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers n and k (1≤n≤1001≤k≤100) — the number of elements in array and the element which must be the most common.

The second line of each test case contains n integers a1a2a3……an (1≤ai≤100) — elements of the array.

Output

For each test case output "YES" if there exists a subsegment in which k is the most common element, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

Example
input
7
5 4
1 4 3 4 1
4 1
2 3 4 4
5 6
43 5 60 4 2
2 5
1 5
4 1
5 3 3 1
1 3
3
5 3
3 4 1 5 5
output
YES
NO
NO
YES
YES
YES
YES
Note

In the first test case we need to check if there is a subsegment where the most common element is 4.

On the subsegment [2,5] the elements are 4, 3, 4, 1

  • 4 appears 2 times;
  • appears 1 time;
  • appears 1 time.

This means that 4 is the most common element on the subsegment [2,5], so there exists a subsegment where 4 is the most common element.

题目大意

t组数据,输入n,g,n个数据,询问是否存在数组的非空子集中的最大出现次数的元素为g

HINT

只要查询到g出现就满足条件 

代码

#include
using namespace std;
const int N=1005;
int a[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n,k,flag=0;//设置标记
        cin>>n>>k;
        for(int i=0;i>a[i];
            if(a[i]==k){
                flag=1;//找到就退出
            }
        }
        if(flag==1) cout<<"YES"<

Aleksa and Stack

After the Serbian Informatics Olympiad, Aleksa was very sad, because he didn't win a medal (he didn't know stack), so Vasilije came to give him an easy problem, just to make his day better.

Vasilije gave Aleksa a positive integer n(n≥3) and asked him to construct a strictly increasing array of size n of positive integers, such that

  • 3⋅ai+2 is not divisible by ai+ai+1 for each i(1≤i≤n−2).
Note that a strictly increasing array aof size n is an array where ai for each i (1≤i≤n−1).

Since Aleksa thinks he is a bad programmer now, he asked you to help him find such an array.

Input

Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer n (3≤n≤2⋅10^5) — the number of elements in array.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output n integers a1,a2,a3,…,an (1≤ai≤10^9).

It can be proved that the solution exists for any n. If there are multiple solutions, output any of them.

Example
input
3
6
7
output
6 8 12
7 11 14 20 22 100
9 15 18 27 36 90 120
Note

In the first test case, a1=6a2=8a3=12, so a1+a2=14 and 3⋅a3=36, so 3⋅a3 is not divisible by a1+a2.

题目大意

t组数据,每组数据由n项严格递增的数组组成,3*an不能被(an-1+an-2)整除,输出这样的数列

HINT

提前设置a0,a1,循环2~n,count持续递增,直至count不能被(ai-1+ai-2)整除,把count值赋给ai

代码

#include
using namespace std;
const int N=2e5+5;
int a[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        a[0]=2;a[1]=3;//遵循递增的条件下任意设置值
        int count=4; 
        for(int i=2;i

 

Vasilije in Cacak

Aca and Milovan, two fellow competitive programmers, decided to give Vasilije a problem to test his skills.

Vasilije is given three positive integers: nk, and x, and he has to determine if he can choose k distinct integers between 1 and n, such that their sum is equal to x.

Since Vasilije is now in the weirdest city in Serbia where Aca and Milovan live, Cacak, the problem seems weird to him. So he needs your help with this problem.

Input

The first line contains a single integer t (1≤t≤10^4) — the number of test cases.

The only line of each test case contains three integers nk and x (1≤n≤2⋅10^51≤k≤n1≤x≤4⋅10^10) — the maximum element he can choose, the number of elements he can choose and the sum he has to reach.

Note that the sum of n over all test cases may exceed 2⋅1052⋅105.

Output

For each test case output one line: "YES", if it is possible to choose k distinct integers between 1and n, such that their sum is equal to x, and "NO", if it isn't.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

Example
input
12
5 3 10
5 3 3
10 10 55
6 5 20
2 1 26
187856 87856 2609202300
200000 190000 19000000000
28 5 2004
2 2 2006
9 6 40
47202 32455 613407217
185977 145541 15770805980
output
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
Note

In the first test case n=5, k=3, x=10, so we can choose the numbers: 235, whose sum is 10, so the answer is "YES".

In the second test case n=5, k=3, x=3, there is no three numbers which satisfies the condition, so the answer is "NO". It can be shown that there are no three numbers whose sum is 3.

题目大意

t组数据,在1~n中,选择k个数字,和可能为x输出“YES”,否则输出“NO”

   HINT

在1~n中,选择k个数字,和的值从min=(1+2...+k),到max=(n-k+1,n-k+2...n),所以只要x在min~max区间中,即满足条件。

·min,max求值要直接公式计算,用for循环累加会超时

代码 

#include
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        long long n,k,x;cin>>n>>k>>x;
        long long min=((1+k)*k)/2,max=(((n-k+1)+n)*k)/2;
        //cout<=min){
            cout<<"YES"<

你可能感兴趣的:(c++)