2017-5-7-Train: Codeforces Round #322 (Div. 2)

A. Vasya the Hipster(水题)

One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.

Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn‘t want to wash them.

Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he‘s got.

Can you help him?

Input

The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya‘s got.

Output

Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he‘s got.

Keep in mind that at the end of the day Vasya throws away the socks that he‘s been wearing on that day.

Examples

input

3 1

output

1 1

input

2 3

output

2 0

input

7 3

output

3 2

Note

In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.

Code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int r , b;
 6     scanf("%d%d" , &r , &b);
 7     int tr = min(r , b);
 8     int al = max(r - tr , b - tr) / 2;
 9     printf("%d %d" , tr , al);
10 }

B. Luxurious Houses(后缀最大 + 模拟)

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let‘s enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers h**i (1 ≤ h**i ≤ 109), where h**i equals the number of floors in the i-th house.

Output

Print n integers a1, a2, ..., a**n, where number a**i is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then a**i should be equal to zero.

All houses are numbered from left to right, starting from one.

Examples

input

5
1 2 3 1 2

output

3 2 0 2 0 

input

4
3 2 1 4

output

2 3 4 0 

Code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 static const int MAXN = 1e5 + 10;
 4 int n;
 5 int data[MAXN];
 6 int tail[MAXN];
 7 int main()
 8 {
 9     scanf("%d" , &n);
10     for(int i = 1 ; i <= n ; ++i)
11     {
12         scanf("%d" , data + i);
13     }
14     for(int i = n ; i > 0 ; --i)
15     {
16         tail[i] = max(tail[i + 1] , data[i + 1]);
17     }
18     for(int i = 1 ; i <= n ; ++i)
19     {
20         printf("%d " , max(tail[i] + 1 - data[i] , 0));
21     }
22 }

C. Developing Skills(计数排序 + 技巧)

Petya loves computer games. Finally a game that he‘s been waiting for so long came out!

The main character of this game has n different skills, each of which is characterized by an integer a**i from 0 to 100. The higher the number a**i is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.

At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya‘s character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero‘s skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.

Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.

Input

The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya‘s disposal.

The second line of the input contains a sequence of n integers a**i (0 ≤ a**i ≤ 100), where a**i characterizes the level of the i-th skill of the character.

Output

The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.

Examples

input

2 4
7 9

output

2

input

3 8
17 15 19

output

5

input

2 2
99 100

output

20

Note

In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor +  lfloor frac{100}{10} rfloor = 10 + 10 =  20.

In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .

In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to .

Code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 static const int MAXN = 1e5 + 10;
 4 int n , k;
 5 int ans;
 6 int data[MAXN];
 7 int has[MAXN];
 8 int main()
 9 {
10     scanf("%d%d" , &n , &k);
11     for(int i = 1 ; i <= n ; ++i)
12     {
13         scanf("%d" , &data[i]);
14         ++has[data[i] % 10];
15         ans += data[i] / 10;
16     }
17     for(int i = 1 ; i < 10 ; ++i)
18     {
19         int s = min(has[10 - i] , k / i);
20         k -= i * s;
21         ans += s;
22         if(s != has[10 - i])
23             break;
24     }
25     ans += min(10 * n - ans , k / 10);
26     printf("%d" , ans);
27 }

D. Three Logos(枚举)

Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.

Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.

Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.

Input

The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where x**i and y**i determine the length and width of the logo of the i-th company respectively.

Output

If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes).

If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that:

  • the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,
  • the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,
  • the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company,

Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn‘t have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them.

See the samples to better understand the statement.

Examples

input

5 1 2 5 5 2

output

5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC

input

4 4 2 6 4 2

output

6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

Code:

 1 #include <bits/stdc++.h>
 2
 3 #define eps 1e-5
 4 #define inf 0x3f3f3f3f
 5 #define max(a,b) ((a)>(b)?(a):(b))
 6 #define min(a,b)  ((a)<(b)?(a):(b))
 7 #define lson l,m,rt<<1
 8 #define rson m+1,r,rt<<1 | 1
 9 #define lc rt<<1
10 #define rc rt<<1 | 1
11 #define getx2(a)  ((a)*(a))
12 #define Pi acos(-1.0)
13
14 typedef long long LL;
15 using namespace std;
16 int main()
17 {
18     int p[3][2];
19     char c[3]= {‘A‘,‘B‘,‘C‘};
20     scanf("%d%d%d%d%d%d",&p[0][0],&p[0][1],&p[1][0],&p[1][1],&p[2][0],&p[2][1]);
21     if(p[0][0]<p[0][1])swap(p[0][0],p[0][1]);
22     if(p[1][0]<p[1][1])swap(p[1][0],p[1][1]);
23     if(p[2][0]<p[2][1])swap(p[2][0],p[2][1]);
24     int sum=0;
25     for(int i=0; i<3; i++)
26     {
27         sum+=p[i][0]*p[i][1];
28     }
29     int n=sqrt(sum);
30     if(sum!=n*n)
31     {
32         printf("-1\n");
33         return 0;
34     }
35     if(p[0][0]==p[1][0]&&p[1][0]==p[2][0]&&(p[0][0]==n&&p[0][1]+p[1][1]+p[2][1]==n))///情况1
36     {
37         printf("%d\n",n);
38         for(int k=0; k<3; k++)
39             for(int i=0; i<p[k][1]; i++)
40             {
41                 for(int j=0; j<p[k][0]; j++)
42                     printf("%c",c[k]);
43                 printf("\n");
44             }
45     }
46     else
47     {///枚举情况2
48         for(int r=0; r<3; r++)
49         {
50             for(int cc=0; cc<3; cc++)
51             {
52                 if(r!=cc)
53                 {
54                     for(int i=0; i<2; i++)
55                     {
56                         for(int j=0; j<2; j++)
57                         {
58                             int kk;
59                             if((r==0&&cc==1)||(r==1&&cc==0))kk=2;
60                             if((r==1&&cc==2)||(r==2&&cc==1))kk=0;
61                             if((r==2&&cc==0)||(r==0&&cc==2))kk=1;
62                             if(p[r][i]+p[cc][j]==n&&p[r][(i+1)%2]+p[kk][1]==n&&p[kk][0]==n)//找到方案
63                             {
64                                 printf("%d\n",n);///输出
65                                 for(int rr=0; rr<p[r][(i+1)%2]; rr++)
66                                 {
67                                     for(int ccc=0; ccc<p[r][i]; ccc++)printf("%c",c[r]);
68                                     for(int ccc=0; ccc<p[cc][j]; ccc++)printf("%c",c[cc]);
69                                     printf("\n");
70                                 }
71                                 for(int rr=0; rr<p[kk][1]; rr++)
72                                 {
73                                     for(int ccc=0; ccc<p[kk][0]; ccc++)
74                                         printf("%c",c[kk]);
75                                     printf("\n");
76                                 }
77                                 return 0;
78                             }
79
80                         }
81                     }
82                 }
83             }
84         }//找不到方案输出-1
85         printf("-1\n");
86     }
87     return 0;
88 }

时间: 2024-08-04 17:37:49

2017-5-7-Train: Codeforces Round #322 (Div. 2)的相关文章

树形dp - Codeforces Round #322 (Div. 2) F Zublicanes and Mumocrates

Zublicanes and Mumocrates Problem's Link Mean: 给定一个无向图,需要把这个图分成两部分,使得两部分中边数为1的结点数量相等,最少需要去掉多少条边. analyse: 树形dp. dp[cur][i][j]:当cur为i集合的时候 有j个和i同集合的方案 状态转移方程为: dp[cur][i][j+k] = min{dp[to][i^1][j=(叶子个数-d)]+dp[cur][i][k]+1,dp[to][i][j]+dp[cur][i][k]} c

Codeforces Round #322 (Div. 2)

F. Zublicanes and Mumocrates 树形dp 题意给了一棵树 要求使得这棵树所有的节点分为两个阵营,其中叶子节点要均分,求最少的两个阵营相邻, 也就是求 最少的边使得 这些边两头阵营不同 dp[cur][i][j] 表示当cur为i阵营的时候 有j个和i同阵营的方案 dp[cur][i][j+k] = min{dp[to][i^1][j=(叶子个数-d)]+dp[cur][i][k]+1,dp[to][i][j]+dp[cur][i][k]} cnt为叶子节点的个数 最后答

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路的权值大于该点最短距离的显然可以删去,否则将该条边加入图中,再求最短路,记录每个点的前一个点,然后又枚举铁路,已经删去的就不用处理了,如果铁路权值大于该点最短距离又可以删去,权值相等时,该点的前一个点如果不为1,则这个点可以由其他路到达,这条铁路又可以删去. 由于本题中边比较多,最多可以有8x10^

Codeforces Round #515 (Div. 3)

Codeforces Round #515 (Div. 3) 1 #include<bits/stdc++.h> 2 #include<iostream> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cstring> 6 #include<cmath> 7 #include<algorithm> 8 #include<queue> 9 #include&l

Codeforces Round #542 (Div. 2)

Codeforces Round #542 (Div. 2) 题目做不下去的我写一写题解 A. Be Positive 水题,考虑正数,负数个数是否\(\geq \lceil \frac{n}{2} \rceil\) B. Two Cakes 给定位置大小为1...n的蛋糕,每种大小共两份,要求两个人从最左边的位置增序各取1..n的蛋糕,求最小步长 两个一起考虑,取到第i块蛋糕,两人的位置状态是确定的,无论是a,b两人怎样分布总是占据了这个位置,有点类似蚂蚁相遇后逆行的想法 所以我们只需min(

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我