码迷,mamicode.com
首页 > 其他好文 > 详细

国庆练习3

时间:2018-10-06 12:04:32      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:name   cstring   alc   OLE   oss   code   app   relative   scanf   

Benches CF 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 mmpeople 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 n(1n100) — the number of benches in the park.

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

Each of the next nn lines contains a single integer ai (1ai100) — 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.

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 kk equal to 15, as there is just a single bench in the park and all 10 people will occupy it.

 

题目意思:

有n个长椅,依次给出每张椅子上最初有的人数,现在增加m个人,这m个人可以随意选择座位,k代表是所有长椅中最大的人数,最后求k的最大值与最小值。

解题思路:

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

k(min) = 既保证坐的人数量最大,又要求此时的k最小,那么只能是平均分。但平均分完人数之后,很有可能均分的人数是要比你起初最大的人数要小,所以需要比较一下。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define ll long long int
 5 using namespace std;
 6 int a[110];
 7 int main()
 8 {
 9     int n,m,i,j,sum,maxs,x,y;
10     scanf("%d%d",&n,&m);
11     sum=0;
12     maxs=0;
13     for(i=0;i<n;i++)
14     {
15         scanf("%d",&a[i]);
16         sum+=a[i];
17         if(a[i]>maxs)
18         {
19             maxs=a[i];
20         }
21     }
22     y=maxs+m;
23     sum+=m;
24     if(sum%n)
25     {
26         x=sum/n+1;
27     }
28     else
29     {
30         x=sum/n;
31     }
32     x=max(x,maxs);
33     printf("%d %d\n",x,y);
34     return 0;
35 }

 

Relatively Prime Pairs CF 1051B

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

You want to split these numbers into exactly rl+12 pairs in such a way that for each pair (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 (1l<r1018rl+13105(rl) is odd).

Output

If any solution exists, print "YES" in the first line. Each of the next rl+12lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (rl+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,并且把每一对按要求输出。
解题思路:算是一个性质吧,相邻两个数的GCD必为1。一奇一偶。注意数据范围,开long long。
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define ll long long int
 5 using namespace std;
 6 int main()
 7 {
 8     ll l,r,i;
 9     scanf("%lld%lld",&l,&r);
10     printf("YES\n");
11     for(i=l;i<=r;i+=2)
12     {
13         printf("%lld %lld\n",i,i+1);
14     }
15     return 0;
16 }

 




国庆练习3

标签:name   cstring   alc   OLE   oss   code   app   relative   scanf   

原文地址:https://www.cnblogs.com/wkfvawl/p/9746812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!