Processing math: 100%

Educational Codeforces Round #108 ABCD ​Solutions

A. Red and Blue Beans

Solution:

Take the minimum value of r and b as min and the maximum value as max.

Then distribute them to maxmin packets. Each packet put only 1 red bean and 1 blue bean.

Then the rest of the max is divided into each packet to see if there are packets more than d beans.

Code:

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

B. The Cake Is a Lie

Solution:

The cost is fixed. The cost must be n1+(m1)×n.

Code

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

C. Berland Regional

Solution:

Calculate the prefix sum of skill point of student at each university. Then directly solve it with brute force.

It will not get TLE. Because for each university, we can skip when the k exceed the number of students.

Code:

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

D. Maximum Sum of Products

Solution:

It can be regarded as a DP problem, although its essence is brute force.

Define base=ni=1aibi. Which is the sum without reverse anything.

We define dp[i][j] to represent the sum after reversed [i,j] from a. It's not hard to find that: dp[i][j]=a[i]b[j]+a[j]b[i](a[i]b[i]+a[j]b[j])+dp[i+1][j1]+base

Of course, dp[i][i]=base. And dp[i][i+1] is quite easy to find out.

Code:

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