There are n benches in the Berland Central park. It is known that ai people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available.
Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k.
Nobody leaves the taken seat during the whole process.
Input
The first line contains a single integer n (1≤n≤100) — the number of benches in the park.
The second line contains a single integer m (1≤m≤10000) — the number of people additionally coming to the park.
Each of the next n lines contains a single integer ai (1≤ai≤100) — the initial number of people on the i-th bench.
Output
Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park.
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 k is 3. 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 k is 7. That requires all six new people to occupy the same bench.
The second example has its minimum k equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
题意:
有n个长椅,椅子上起初有 a【i】个人,现在增加m个人,这 m个人可以随意选择座位
k代表的是最大数量的人坐在长椅上,最后求k的最大值与最小值
k(max) = 所有的m个人坐在起初人最多的地方
k(min) = 既保证坐的人数量最大,又要求此时的k最小,那么只能是平均分
需要注意的是:
求 k的最小值的时候,平均分完人数之后,很有可能均分的人数是要比你起初最大的人数要小,所以需要比较一下(我这里就是卡住了,一直WA下去)
当然只有一个长椅的时候,不管来多少人,都只能坐在同一个位置,k的最大与最小值是相同的
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
Berland shop sells n kinds of juices. Each juice has its price ci. 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 n (1≤n≤1000) — the number of juices.
Each of the next n lines contains an integer ci (1≤ci≤100000) and a string si — the price of the i-th juice and the vitamins it contains. String si contains from 1 to 3 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 si. The order of letters in strings si 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=15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
You are given an array a consisting of n integers. You can perform the following operations with it:
Choose some positions i and j (1≤i,j≤n,i≠j), write the value of ai⋅aj into the j-th cell and remove the number from the i-th cell;
Choose some position i and remove the number from the i-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−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 n (2≤n≤2⋅105) — the number of elements in the array.
The second line contains n integers a1,a2,…,an (−109≤ai≤109) — the elements of the array.
Output
Print n−1 lines. The k-th line should contain one of the two possible operations.
The operation of the first type should look like this: 1 ik jk, where 1 is the type of operation, ik and jk are the positions of the chosen elements.
The operation of the second type should look like this: 2 ik, where 2 is the type of operation, ik 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]→ [X,X,X,−10,−3]→[X,X,X,X,30]. Thus, the maximum answer is 30. Note, that other sequences that lead to the answer 30 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]→ [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]→ [40,X,X,X,X].
The third example can have the following sequence of transformations of the array: [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].
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].
Vasya came up with a password to register for EatForces — a string s. 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 s is a string x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1). len is the length of the substring. Note that the empty string is also considered a substring of s, it has the length 0.
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 s 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 T (1≤T≤100) — the number of testcases.
Each of the next T lines contains the initial password s (3≤|s|≤100), consisting of lowercase and uppercase Latin letters and digits.
Only T=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 0. 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 4, because the changed positions are 2 and 5, thus (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).
题意:给一个密码s,然后输出包含大小写字母和数字
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
You are given a set of all integers from l to r inclusive, l You want to split these numbers into exactly r−l+12 pairs in such a way that for each pair (i,j) the greatest common divisor of i and j is equal to 1. 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 Output If there are multiple solutions, print any of them. If there exists no solution, print “NO”. Example
The only line contains two integers l and r (1≤l
If any solution exists, print “YES” in the first line. Each of the next r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r−l+1) numbers should be pairwise distinct and should have values from l to r inclusive.
Input
1 8
Output
YES
2 7
4 1
3 8
6 5
题意:找出l~r之间gcd为1的数对,输出多种情况,所以我们可以观察的到连续的奇数和偶数在一起的话,gcd就是1.#include