國慶練習3
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
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)
Each of the next nn lines contains a single integer ai (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
Examples
Input4Output
6
1
1
1
1
3 7Input
1Output
10
5
15 15Input
3Output
6
1
6
5
6 12Input
3Output
7
1
6
5
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, (r−l+1)≤3⋅105and (r−l) is always odd.
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 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≤1018, r−l+1≤3⋅105, (r−l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next r−l+12lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (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
Input1 8Output
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