Codeforces Global Round 14 ABCD Solutions

A. Phoenix and Gold

Solution:

If the sum of all numbers in w is x, then there is no solution. Because no matter what order, when $i=n$, the sum will be x.

Otherwise, because of values in w is distinct. So, if we found sum is x for some position i. We can swap $w_i$ and $w_{i+1}$.
For example, w is (1,2,3,4), and x is 3. We can swap 2 and 3.

Code:

Submission #114960365 - Codeforces
Codeforces. Programming competitions and contests, programming community

B. Phoenix and Puzzle

Solution:

Two and four right isosceles triangles can make a square.

So, we just need copy and expand it by this way:

Code:

Submission #114961841 - Codeforces
Codeforces. Programming competitions and contests, programming community

C. Phoenix and Towers

Solution:

Greedy. Every time, get the tower which height is the minimum one. And we put a block on it. Because $h<x$. So, after that, the height of current tower can't be higher than others by x.

Code:

Submission #114960434 - Codeforces
Codeforces. Programming competitions and contests, programming community

D. Phoenix and Socks

Solution:

Let's say the number of left socks is lesser than the right one.

Greedy. First, we pair the left socks with the right without any color change.
Then we move right socks which can find the same color sock in the right to left one by one. And pair them.
After the operation above. There is no sock with the same color on the right. And the color of all socks on the right is different from the color on the left. So, move right socks to left and change the color of remaining right socks.

Code:

Submission #114960470 - Codeforces
Codeforces. Programming competitions and contests, programming community
DigitalOcean Referral Badge 蜀ICP备19018968号