CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes) A-B

C之后的尚未看题解

A:

A. Good Pairs

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array a1,a2,…,ana1,a2,…,an of positive integers. A good pair is a pair of indices (i,j)(i,j) with 1≤i,j≤n1≤i,j≤n such that, for all 1≤k≤n1≤k≤n, the following equality holds:

|ai−ak|+|ak−aj|=|ai−aj|,|ai−ak|+|ak−aj|=|ai−aj|,

where |x||x| denotes the absolute value of xx.

Find a good pair. Note that ii can be equal to jj.

Input

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

The first line of each test case contains an integer nn (1≤n≤1051≤n≤105) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) where aiai is the ii-th element of the array.

The sum of nn for all test cases is at most 2⋅1052⋅105.

Output

For each test case, print a single line with two space-separated indices ii and jj which form a good pair of the array. The case i=ji=j is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.

Example

input

Copy

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

output

Copy

2 3
1 2
1 1

Note

In the first case, for i=2i=2 and j=3j=3 the equality holds true for all kk:

  • k=1k=1: |a2−a1|+|a1−a3|=|2−5|+|5−7|=5=|2−7|=|a2−a3||a2−a1|+|a1−a3|=|2−5|+|5−7|=5=|2−7|=|a2−a3|,
  • k=2k=2: |a2−a2|+|a2−a3|=|2−2|+|2−7|=5=|2−7|=|a2−a3||a2−a2|+|a2−a3|=|2−2|+|2−7|=5=|2−7|=|a2−a3|,
  • k=3k=3: |a2−a3|+|a3−a3|=|2−7|+|7−7|=5=|2−7|=|a2−a3||a2−a3|+|a3−a3|=|2−7|+|7−7|=5=|2−7|=|a2−a3|.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,n,p,q;
const int maxn=1e5+5;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--)
    {
        int mmax=0;
        int mmin=1e9+5;
        cin>>n;
        for(int i=1; i<=n; i++)
        {
            cin>>a[i];
            if(a[i]>mmax)
            {
                mmax=a[i];
                p=i;
            }
            if(a[i]<mmin)
            {
                mmin=a[i];
                q=i;
            }
        }
        cout<<min(p,q)<<" "<<max(p,q)<<endl;
    }
    return 0;
}

B:

B. Subtract Operation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a list of nn integers. You can perform the following operation: you choose an element xx from the list, erase xx from the list, and subtract the value of xx from all the remaining elements. Thus, in one operation, the length of the list is decreased by exactly 11.

Given an integer kk (k>0k>0), find if there is some sequence of n−1n−1 operations such that, after applying the operations, the only remaining element of the list is equal to kk.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and kk (2≤n≤2⋅1052≤n≤2⋅105, 1≤k≤1091≤k≤109), the number of integers in the list, and the target value, respectively.

The second line of each test case contains the nn integers of the list a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109).

It is guaranteed that the sum of nn over all test cases is not greater that 2⋅1052⋅105.

Output

For each test case, print YES if you can achieve kk with a sequence of n−1n−1 operations. Otherwise, print NO.

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

Example

input

Copy

4
4 5
4 2 2 7
5 4
1 9 1 3 4
2 17
17 0
2 17
18 18

output

Copy

YES
NO
YES
NO

Note

In the first example we have the list {4,2,2,7}{4,2,2,7}, and we have the target k=5k=5. One way to achieve it is the following: first we choose the third element, obtaining the list {2,0,5}{2,0,5}. Next we choose the first element, obtaining the list {−2,3}{−2,3}. Finally, we choose the first element, obtaining the list {5}{5}.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,n,k;
const int maxn=2e5+5;
ll a[maxn];

int lowbou(ll a[],ll l,ll r,ll tar)
{
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if (a[mid]<tar) l=mid+1;
        else r=mid-1;
    }
    return l;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--)
    {
        memset(a,0,sizeof(a));
        cin>>n>>k;
        bool flag=0;
        for(ll i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        for(ll i=1; i<=n; i++)
        {
            ll y=lowbou(a,1,n,a[i]+k);
            if(y<=n)
            {
                if(a[y]==a[i]+k)
                {
                    cout<<"YES"<<endl;
                    flag=1;
                    break;
                }

            }
        }
        if(flag==0)
            cout<<"NO"<<endl;
    }
    return 0;
}

关于b题的两个坑点,一开始我没有初始化memset(a,0,sizeof(a)),导致指针到了n+1还有数,初始化以后,还是错,原因在于比如2 -2          -2 -1这组数据,我-2一直搜,最后加上0刚好是-2,所以指针不能大于n,也就是必须小于等于n。题解用的是set,我看有map,上完课,回来补

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值