This problem can be solved by DPDP. For each type ii, Camila has three choices - buy ii-th type, buy n+1in+1-i-th type or skip both. So, if we group each ii and n+1in+1-i type, there will be total n/2n/2 groups. Now, take groups and buy count as state of dp and in each dp state there will be three transitions as skip this group, greedily buy books from ii-th type and greedily buy books from n+1in+1-i-th type and then return the minimum price among them. Overall complexity will be O(XK)O(X * K).

Statistics

86% Solution Ratio
adnan_tokyEarliest, Jul '21
Nafis2003174.132453Fastest, 0.0s
mustafiz_voidLightest, 9.5 kB
antihashShortest, 1434B
Toph uses cookies. By continuing you agree to our Cookie Policy.