国庆个人赛——NO.3

1、

Codeforces——1042A

There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn available.

Let kk be the maximum number of people sitting on one bench after additional mm people came to the park. Calculate the minimum possible kk and the maximum possible kk.

Nobody leaves the taken seat during the whole process.

Input

The first line contains a single integer nn (1≤n≤100)(1≤n≤100) — the number of benches in the park.

The second line contains a single integer mm (1≤m≤10000)(1≤m≤10000) — the number of people additionally coming to the park.

Each of the next nn lines contains a single integer aiai (1≤ai≤100)(1≤ai≤100) — the initial number of people on the ii-th bench.

Output

Print the minimum possible kk and the maximum possible kk, where kk is the maximum number of people sitting on one bench after additional mm people came to the park.

扫描二维码关注公众号,回复: 3876876 查看本文章

Examples

Input

4
6
1
1
1
1

Output

3 7

Input

1
10
5

Output

15 15

Input

3
6
1
6
5

Output

6 12

Input

3
7
1
6
5

Output

7 13

Note

In the first example, each of four benches is occupied by a single person. The minimum kk is 33. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum kk is 77. That requires all six new people to occupy the same bench.

The second example has its minimum kk equal to 1515 and maximum kk equal to 1515, as there is just a single bench in the park and all 1010 people will occupy it.

题意:

有n个长椅,椅子上起初有 a【i】个人,现在增加m个人,这 m个人可以随意选择座位

k代表的是最大数量的人坐在长椅上,最后求k的最大值与最小值

k(max) = 所有的m个人坐在起初人最多的地方

k(min)  = 既保证坐的人数量最大,又要求此时的k最小,那么只能是平均分

需要注意的是:

求 k的最小值的时候,平均分完人数之后,很有可能均分的人数是要比你起初最大的人数要小,所以需要比较一下(我这里就是卡住了,一直WA下去)

当然只有一个长椅的时候,不管来多少人,都只能坐在同一个位置,k的最大与最小值是相同的

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int main()
{
    int n,k;
    int a[100+10];

    scanf("%d",&n);
    scanf("%d",&k);

    int maxx=-1;
    int minn=INF;
    int sum=0;

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);

        sum+=a[i];

        if(a[i]>maxx)
            maxx=a[i];
    }

    int m,mm;

    if(n==1)
        printf("%d %d\n",a[0]+k,a[0]+k);

    else
    {

        m=maxx+k;

        sum+=k;

        if(sum%n==0)
            mm=sum/n;

        else
            mm=sum/n+1;

        mm=max(mm,maxx); // 这里需要注意下

        printf("%d %d\n",mm,m);



    }
}

2、

Codeofrces——1042B

Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.

Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.

Input

The first line contains a single integer nn (1≤n≤1000)(1≤n≤1000) — the number of juices.

Each of the next nn lines contains an integer cici (1≤ci≤100000)(1≤ci≤100000) and a string sisi — the price of the ii-th juice and the vitamins it contains. String sisi contains from 11 to 33 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string sisi. The order of letters in strings sisi is arbitrary.

Output

Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.

Examples

Input

4
5 C
6 B
16 BAC
4 A

Output

15

Input

2
10 AB
15 BA

Output

-1

Input

5
10 A
9 BC
11 CA
4 A
5 B

Output

13

Input

6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA

Output

250

Input

2
5 BA
11 CB

Output

16

Note

In the first example Petya buys the first, the second and the fourth juice. He spends 5+6+4=155+6+4=15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 1616, which isn't optimal.

In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".

题意:

Petya想要去补充一些维他命,他必须通过买一些果汁并喝掉才能吸收果汁中的维他命,这些果汁各有一些价格

维他命包括 A、B、C,已知某些果汁中含有不同类型的维他命,有的含有 A、AB、ABC、B、等等

求补充A、B、C 维他命所需要的最少费用是多少

思路:

对于这个题我就是完全暴力模拟求解了

我用了结构体和好多数组,后来发现结构体是用不到的

如果想补充A、B、C的话,可以分为以下几种类型:

1、买含有单独的A、B、C的果汁

2、买含有 ABC的果汁

3、买两瓶

  AB+BC、AB+AC、AB+C、BC+AB、BC+AC、BC+A、AC+AB、AC+BC、AC+B

  注意到有重复的情况,去重之后为

  AB+BC、AB+AC、AB+C、BC+AC、BC+A、AC+B

然后去比较这几种情况哪一种花的钱数最少就可以

首先给价格赋值为最大 ,但需要注意的是不能定义为 0x3f3f3f3f ,当三个都为最大值加起来的时候,有可能超int 的范围,所以定义 INF= 0x3f3f3f

需要注意最后一种样例

并没有出现A、B、C、这一种情况,所以ans=v(A)+v(B)+v(C)> INF ,输出 %d的形式是 < 0 的,

所以特判一下,如果值小于0的话,直接定义为最大INF

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f

struct NODE
{
    int a;
    char s[10];
} node[1000+10];

int vis[1000+10];

int main()
{
    int n;
    scanf("%d",&n);

    int v[10];
    int x[10];
    int xx[10];
    memset(v,INF);
    memset(x,INF);
    memset(xx,INF);

    memset(vis,0);
    for(int i=0; i<n; i++)
    {
        scanf("%d %s",&node[i].a,&node[i].s);


        if(strcmp(node[i].s,"A")==0)
            v[0]=min(node[i].a,v[0]),vis[0]=1;
        if(strcmp(node[i].s,"B")==0)
            v[1]=min(node[i].a,v[1]),vis[1]=1;
        if(strcmp(node[i].s,"C")==0)
            v[2]=min(node[i].a,v[2]),vis[2]=1;
        if(strcmp(node[i].s,"AB")==0||strcmp(node[i].s,"BA")==0)
            x[0]=min(node[i].a,x[0]),vis[0]=1,vis[1]=1;
        if(strcmp(node[i].s,"AC")==0||strcmp(node[i].s,"CA")==0)
            x[1]=min(x[1],node[i].a),vis[0]=1,vis[2]=1;
        if(strcmp(node[i].s,"BC")==0||strcmp(node[i].s,"CB")==0)
            x[2]=min(node[i].a,x[2]),vis[1]=1,vis[2]=1;
        if(strcmp(node[i].s,"ABC")==0||strcmp(node[i].s,"ACB")==0
                ||strcmp(node[i].s,"CAB")==0||strcmp(node[i].s,"CBA")==0
                ||strcmp(node[i].s,"BAC")==0||strcmp(node[i].s,"BCA")==0)
            xx[0]=min(node[i].a,xx[0]),vis[0]=1,vis[1]=1,vis[2]=1;
    }

   // printf("%d %d %d\n",vis[0],vis[1],vis[2]);

    if(vis[0]==0||vis[1]==0||vis[2]==0)
        printf("-1\n");
    else
    {
        int a,b,c,d,e;
//        a=INF,b=INF,c=INF,d=INF,e=INF;

        int ans;
        ans=INF;
        a=v[0]+v[1]+v[2];
        if(a<0)
            a=INF;
//        cout<<a<<endl;
//        cout<<ans<<endl;
        ans=min(ans,a);

        b=xx[0];
        if(b<0)
            b=INF;
        ans=min(ans,b);

        c=x[0]+v[2];
        if(c<0)
            c=INF;
        ans=min(ans,c);

        d=x[1]+v[1];
        if(d<0)
            d=INF;
        ans=min(d,ans);

        e=x[2]+v[0];
        if(e<0)
            e=INF;
        ans=min(e,ans);

        ans=min(ans,x[0]+x[1]);
        ans=min(ans,x[0]+x[2]);
        ans=min(ans,x[1]+x[2]);

        printf("%d\n",ans);
    }

}

3、

Codeforces——1042C

You are given an array aa consisting of nn integers. You can perform the following operations with it:

  1. Choose some positions ii and jj (1≤i,j≤n,i≠j1≤i,j≤n,i≠j), write the value of ai⋅ajai⋅aj into the jj-th cell and remove the number from the ii-th cell;
  2. Choose some position ii and remove the number from the ii-th cell (this operation can be performed no more than once and at any point of time, not necessarily in the beginning).

The number of elements decreases by one after each operation. However, the indexing of positions stays the same. Deleted numbers can't be used in the later operations.

Your task is to perform exactly n−1n−1 operations with the array in such a way that the only number that remains in the array is maximum possible. This number can be rather large, so instead of printing it you need to print any sequence of operations which leads to this maximum number. Read the output format to understand what exactly you need to print.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the elements of the array.

Output

Print n−1n−1 lines. The kk-th line should contain one of the two possible operations.

The operation of the first type should look like this: 1 ik jk1 ik jk, where 11 is the type of operation, ikik and jkjk are the positions of the chosen elements.

The operation of the second type should look like this: 2 ik2 ik, where 22 is the type of operation, ikik is the position of the chosen element. Note that there should be no more than one such operation.

If there are multiple possible sequences of operations leading to the maximum number — print any of them.

Examples

Input

5
5 -2 0 1 -3

Output

2 3
1 1 2
1 2 4
1 4 5

Input

5
5 2 0 4 0

Output

1 3 5
2 5
1 1 2
1 2 4

Input

2
2 -1

Output

2 2

Input

4
0 -10 0 0

Output

1 1 2
1 2 3
1 3 4

Input

4
0 0 0 0

Output

1 1 2
1 2 3
1 3 4

Note

Let X be the removed number in the array. Let's take a look at all the examples:

The first example has, for example, the following sequence of transformations of the array: [5,−2,0,1,−3]→[5,−2,X,1,−3]→[X,−10,X,1,−3]→[5,−2,0,1,−3]→[5,−2,X,1,−3]→[X,−10,X,1,−3]→ [X,X,X,−10,−3]→[X,X,X,X,30][X,X,X,−10,−3]→[X,X,X,X,30]. Thus, the maximum answer is 3030. Note, that other sequences that lead to the answer 3030 are also correct.

The second example has, for example, the following sequence of transformations of the array: [5,2,0,4,0]→[5,2,X,4,0]→[5,2,X,4,X]→[X,10,X,4,X]→[5,2,0,4,0]→[5,2,X,4,0]→[5,2,X,4,X]→[X,10,X,4,X]→ [X,X,X,40,X][X,X,X,40,X]. The following answer is also allowed:

1 5 3
1 4 2
1 2 1
2 3

Then the sequence of transformations of the array will look like this: [5,2,0,4,0]→[5,2,0,4,X]→[5,8,0,X,X]→[40,X,0,X,X]→[5,2,0,4,0]→[5,2,0,4,X]→[5,8,0,X,X]→[40,X,0,X,X]→ [40,X,X,X,X][40,X,X,X,X].

The third example can have the following sequence of transformations of the array: [2,−1]→[2,X][2,−1]→[2,X].

The fourth example can have the following sequence of transformations of the array: [0,−10,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0][0,−10,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0].

The fifth example can have the following sequence of transformations of the array: [0,0,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0][0,0,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0].

4、

Codeforces——1051A

Vasya came up with a password to register for EatForces — a string ss. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.

But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not.

A substring of string ss is a string x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1)x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1). lenlen is the length of the substring. Note that the empty string is also considered a substring of ss, it has the length 00.

Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactly once, and the chosen string should have the minimal possible length.

Note that the length of ss should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

Input

The first line contains a single integer TT (1≤T≤1001≤T≤100) — the number of testcases.

Each of the next TT lines contains the initial password s (3≤|s|≤100)s (3≤|s|≤100), consisting of lowercase and uppercase Latin letters and digits.

Only T=1T=1 is allowed for hacks.

Output

For each testcase print a renewed password, which corresponds to given conditions.

The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is 00. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" →→ "a7cdEf" is 44, because the changed positions are 22 and 55, thus (5−2)+1=4(5−2)+1=4.

It is guaranteed that such a password always exists.

If there are several suitable passwords — output any of them.

Example

Input

2
abcDCE
htQw27

Output

abcD4E
htQw27

Note

In the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.

In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).

5、

Codeforces——1051B

You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l+1)≤3⋅105(r−l+1)≤3⋅105 and (r−l)(r−l) is always odd.

You want to split these numbers into exactly r−l+12r−l+12 pairs in such a way that for each pair (i,j)(i,j) the greatest common divisor of ii and jj is equal to 11. Each number should appear in exactly one of the pairs.

Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

Input

The only line contains two integers ll and rr (1≤l<r≤10181≤l<r≤1018, r−l+1≤3⋅105r−l+1≤3⋅105, (r−l)(r−l) is odd).

Output

If any solution exists, print "YES" in the first line. Each of the next r−l+12r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (r−l+1)(r−l+1) numbers should be pairwise distinct and should have values from ll to rr inclusive.

If there are multiple solutions, print any of them.

If there exists no solution, print "NO".

Example

Input

1 8

Output

YES
2 7
4 1
3 8
6 5

题意:

给定两个数 l、r,已知l-r是奇数,那么l、r一个为奇数,一个为偶数

求【l,r】区间两两成对的数,需要满足 gcd(a,b)==1;共有 (l-r+1)/ 2 对

如果满足题意的话,输出YES,并且把每一对按要求输出

思路:

写出从l-r的所有数,可以看出相邻两个数,一个是奇数一个是偶数,那么两个数的gcd肯定为1

并且对于所有的l和r来说,都有(l-r+1)/ 2 对满足题意得,所以不存在NO的这一种情况

对于任意两个数来说,都是YES,并且跑遍循环,输出(l-r+1)/ 2 对数即可

需要开long long

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int main()
{
    LL l,r;
    scanf("%lld %lld",&l,&r);

    LL x;
    x=(r-l+1)/2;

    printf("YES\n");
    for(LL i=l;i<=r;i+=2)
        printf("%lld %lld\n",i,i+1);
}

猜你喜欢

转载自blog.csdn.net/JKdd123456/article/details/82932333