**A: Carrot Cakes**

**B: T-shirt buying**

**C: Fountains**

**D: Field expansion**

**E: Aquarium decoration**

**F: Beautiful fountains rows**

**G: Cut the pie**

# | User | Rating |
---|---|---|

1 | Benq | 3813 |

2 | tourist | 3768 |

3 | maroonrk | 3570 |

4 | Radewoosh | 3535 |

5 | fantasy | 3526 |

6 | jiangly | 3523 |

7 | Um_nik | 3522 |

8 | orzdevinwang | 3441 |

9 | cnnfls_csy | 3427 |

10 | zh0ukangyang | 3423 |

# | User | Contrib. |
---|---|---|

1 | awoo | 180 |

2 | -is-this-fft- | 178 |

3 | nor | 169 |

4 | Um_nik | 168 |

5 | SecondThread | 164 |

6 | maroonrk | 163 |

7 | adamant | 162 |

8 | kostka | 161 |

9 | YouKn0wWho | 158 |

10 | antontrygubO_o | 154 |

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

↑

↓

Codeforces (c) Copyright 2010-2023 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/01/2023 18:38:41 (g2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

What a beatiful solution for D )

What a beautiful solution for E

Someone plz explain me the solution for Carrot Cakes ?

You can simulate the entire process on time ( Since constraints are low. The maximum time it would take to get 1000 cakes is 1e6)

First situation : You only have first oven. Then calculate the time you need to get atleast n cakes.

Second situation : From starting you have first oven. At time t = d , you have second oven too. Simultaneously calculate the time needed to get atleast n cakes.

If time required in second situation is less than first situation , then it is reasonable to build the second oven.

Code

Your simulation seems a bit too complicated. Just forget about the second oven and check whether or not any cakes remain at time d: http://codeforces.com/contest/799/submission/27016758

Won't your code go wrong as per this statement:

If the time needed with the second oven is the same as with one oven, then it is unreasonable.I'm not able to format a test-case so just giving the description of a test-case: If cakes remain after 'd' time but time completion of both procedures is same.

Please correct me if I'm wrong.

Sorry, I got it! Ignore my above comment..!

Can you please explain the problem D bit more?

Edit:I got itCould someone explain this algorithm?

You can find quite short code here http://codeforces.com/blog/entry/48868

For Carrot Cakes, can someone explain how do we get the value (n+k-1)/k*t ?

You need ceil(n/k)*t because you bake k cakes every t seconds and that is the smallest time you need to bake atleast n cakes.

ceil(a/b) is the same as floor((a+b-1)/b) or equivalently, (a+b-1)/b.

please can you tell me why the regular Math.ceil function does not work here ???

We don't need to use bin search in C if we precalcaulated two better fountains for each p <= c and p <= d (I named it C_dp[c+1][2], D_dp[d+1][2]). Then, first ans will be (C_dp[c][0] + D_dp[d][0]) if both of them are non-zero.

Another two cases — we will check each sorted fountain buying for C, and if its cost < p (we still have some money), trying to by second fountain C_dp[c — p][0] (if b of current fountain == C_dp[c — p][0], then we use C_dp[c — p][1]). Also checking if it is non-zero.

The same with D's.

Summary: O(C + D + C * log(C) + D * log(D)) (log for sorting). http://codeforces.com/contest/799/submission/27062024

I don't know why minuses, it's a good approach. However you do not need to sort.

Basically, split fountains into 2 groups {diamonds, coins} and calculate 2 best beauties for each price.

You can do this in a similar way to prefix sum. Store each beauty for initial price (remember max 2 of them). Then go from smallest prices to largest: you have 2 best beauties for price p-1, add them to price p, and leave best 2 for price p.

Then process every fountain f — you have to find the best match for f. You should choose either the best beauty for diamonds-price_in_diamonds(f) or coins-price_in_coins(f). You should store 2 of them, as the best one might be the same as f in which case you have to choose the second best.

Time: O(maxPrice + n) — including coins and diamonds initially possessed.

Ok, I see. We needn't sort because a[i] <= 10^5. Your solution is better, thanks.

Overtaking editorial for E:

If we were able to get to this point, the answer clearly exists — now improve it.

Notice that if we have k items which both players like, then we choose nothing in 2. and we got all the best in 3. So we may remove some of the items taken in 1., to improve the result.

If we got less than k items in step 1, notice that we got all the best in 2. and 3. We obviously don't remove anything from 3. We also don't remove anything from 2 — we took all the best items, to meet the requirement that both of players have to get at least k items.

Which means that we can improve our answer by removing things we got in 1.

We do this in 2 ways:

A. Check the balance of each player. If it has more than k items, you can try to remove item liked by both. There are 2 cases, when you can remove: A.1. Both players have more than k items, then you can replace the current worst item collected in 1. with the best item not collected yet and decrease the number of items for both players.

A.2. If only one player (call him p1) has more than k items, the other has exactly k items (call him p2) but there are still some items which p2 likes (obviously we will not choose anything liked by both, as we selected all the best such items in 1. and now we remove them). We can remove item from 1. and get the best item which p2 likes. Decrease the status for p1 and nothing changed for p2 — it sill has k items.

B. Once we removed everything by A., both players have exactly k items and we can't decrease the status anymore. We still can improve the answer though. We need to remove 2 items taken so far. One of them must be from 1., so the other must not be liked by any player. We replace them with 2 best items: 1 of them liked by p1 and the other by p2. In this way we do not change the number of items which both players like (they still have k of them) and we keep the set of m items.

After A. and B. we finish with the best set possible.

"After that we need to calculate linear dynamic where di equals to maximum width which we got for the length i. Let's iterate through extensions in sorted order and recalculate d." I did'nt find this to be clear enough. Can someone please explain this ?

Let dp[i][x] = the biggest height you can get with width x using i extensions

to calculate next 2 states (multiplying width & height)

dp[i+ 1][x] =dp[i][x] *ext[i+ 1] // multiply heightdp[i+ 1][x*ext[i+ 1]] =dp[i][x] // multiply widththe base case is

dp[0][w] =hwe can reduce the memory and use only 1D array and update states in decreasing order of width

after each new state

dp[i][x] =y, check if (x * y) can enclose the (a*b) rectangle27060296

dp[i+1][x*ext[i+1]] = max(dp[i][x*ext[i+1]], dp[i][x])Could you explain, please, why dp[i+1][x*ext[i+1]] isn't just always equal to dp[i][x*ext[i+1]]? Can't figure whence have you got dp[i][x].

The max height for width

x*ext[i+ 1] usingiextensions can be less than max height for widthxusingiextensions, so we take the max of previous max height for that width (dp[i][x*e]) and max height for the width we are multiplying (dp[i][x])Also the previous max height can be zero

For example:

w= 2,h= 2, extensions {2, 2}This worst case

O(n^{2}) solution for C has passed. It should not have if the test cases had been a little stronger.Should be noted that for E you don't need any particular data structure (such as a stl set) to keep your data. You can just use arrays and remember the last index of pushed "must-have" elements so you can't push them on further steps (in order to mentain O(n)) steps. This way you get O(n) as opposed to O(n log n). Not much of an improvement but it's something.

I don't understand problem C's solution, why should we consider p1 equals p2? In fact, I accepted without considering this case (My code)).

Can you please explain the solution for D?

Dynamic Programming

Meet in the Middle

I have seen solutions of C using fenwick tree( also called Binary Indexed Tree or BIT) such as this one : (http://codeforces.com/contest/799/submission/27019364) Can somebody explain this ?

can anyone give a code with explanation for [problem:D].

Problem D:

I found this is the easiest soln to understand. Note this gets TLE...So first one gets AC just for optimization

Great solution for Problem D!

However, mine is different and I would like to share it.

We reduce the problem to the subproblem: given an array $$$arr[]$$$ and a number $$$X$$$, find a subsequence $$$b[1]$$$, $$$b[2]$$$, ..., $$$b[k]$$$ of $$$arr[]$$$ such that $$$P=b[1]b[2]...b[k] \geq X$$$ and the $$$P$$$ is the smallest possible.

To solve it, we use DP. Sort the array in decreasing order. DP state:

$$$dp[j][ceil(X/i)]$$$ is the answer for $$$arr[1...j]$$$. Then transition is $$$dp[j][ceil(X/i)]=min(dp[j-1][ceil(X/i)], dp[j-1][ceil(X/(iv[j])]*v[j])$$$.

That's it!

103627148

Problem A: Carrot Cakes Note: read question carefully as I mistaken the bake time for second oven as d while it will be t (because after build they run simultaneously)

You can just check whether total time taken to bake all cakes by OVEN1 is greater than the time to bake 1 cake by OVEN2 because if OVEN2 has baked 1 cake in a time lesser than the completion time for all cakes, it means OVEN2 has contributed and thus it has

HELPED.Why n/k? to see how many cakes can be baked parallely?

If you need 9 cakes but oven can bake 2 cakes in 3 sec, so time for 9 cakes is? Time = 3*roundup(9/2)