This is a problem from HackerEarth March Easy'20.
Problem link
Any help will be appreciated!
# | User | Rating |
---|---|---|
1 | tourist | 3947 |
2 | jiangly | 3734 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3612 |
7 | ecnerwala | 3581 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | ksun48 | 3479 |
# | User | Contrib. |
---|---|---|
1 | awoo | 162 |
2 | maomao90 | 160 |
3 | nor | 156 |
4 | cry | 155 |
4 | adamant | 155 |
4 | atcoder_official | 155 |
4 | -is-this-fft- | 155 |
8 | maroonrk | 153 |
9 | SecondThread | 147 |
10 | Petr | 146 |
This is a problem from HackerEarth March Easy'20.
Problem link
Any help will be appreciated!
Name |
---|
.
I think you misunderstood the problem.
If we have given money to some agent and bought a house from him then we don't have to pay him again if we buy another house lying in that agents' range. Although we may have to pay some other agents who are also selling that new house.
SORRY what I wrote before isn't true
I don't know how to solve this problem faster than O(n^3)
cost[l][r] = sum of the costs of the agents whose intervals are completely included in [l,r]
d[j][i] = the maximum profit that you can make by "not buying" i-j houses out of the first i IF you buy the ith house
d[j][i] = max(d[j-1][i-1], max{d[j-1][k] + cost[k+1][i-1] | k < i-1})
the answer is cost[1][n]-d[k][n]
you can calculate d[][] in O(n^3), but I think that if you fix j, and take i < z:
let a be the index (a < i) for which you get the maximum value for d[j][i]
let b be the index (b < z) for which you get the maximum value for d[j][z]
then a < b? if this is true, then you can use divide et impera to calculate d[][] in O(n^2*logn)
Thank you! As per the editorial of this problem we can use CHT to optimize DP.
I guess i need to learn how to use CHT first.