This is a problem from HackerEarth March Easy'20.
Problem link
Any help will be appreciated!
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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.