Real estate agents

3.5

17 votes
2D dynamic programming, Algorithms, Binary Search, Dynamic Programming
Problem

There are m real estate agents in the city. There is a street containing n houses in a straight line and they are numbered from 1 to n. The ith agent sells the houses with numbers from Ii to ri and gets ci dollars as the commission fee. 

Note: The ith agent is paid either 0 or ci dollars. 

If you want to buy a house, then you are required to pay the commission to all the agents selling that house but each agent can be paid at most once.

If you want to buy exactly k houses in the city, then determine the minimum amount of money that you must pay in dollars.

Input format

  • First line: Three space-separated integers n,m, and k denoting the number of houses, the number of agents, and the number of houses you want to buy
  • Next n lines: Three space-separated integers li,ri, and ci denoting the range of houses and the commission earned by the ith agent

Output format

In a single line, print one number that represents the minimum amount of money that you are required to pay to buy exactly k houses.

Constraints

1n20001m1051kn1lirin1ci109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

We can buy houses with numbers [5,6,9,10]. In this situation we have to pay only 5$. (paying the second agent)

Editor Image

?