Codeforces Round #727 ABCD Solutions (Java/C++)

A. Contest Start

Solution:

Each participant will make the following $\frac{t}{x}$ participants dissatisfied. But for last few participants, because no more participants following, so need subtract it.

Code:

Java

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

C++

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

B. Love Song

Solution:

Just count the prefix sum of each letter.

Code:

Java

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

C++

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

C. Stable Groups

Solution:

Let us consider the case that we do not add additional student, group the students directly. We can get this with brute force.

So, the difference between two groups is larger than x. If the difference is less than x after we add some additional students, we can merge these two groups. So, naturally, we sort the differences from small to large, and merge them one by one.

Code:

Java

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

C++

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

D. PriceFixed

We found that the total number of items that we bought will is the sum of a. So, it is just a matter of reversing the order of purchase.
Then we found whether have discount or not is depends on the b and the position of the item.

Codeforces Round #727 PriceFixed Solution (Java/C++)
Solution:For each product, we will buy exactly $a_i$ items. We will not buy more items. So, the total number items we buy will not change (because
Click the link above for detail solution