Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Vidit Shah
Vidit Shah
6,037 Points

Help in Code Challenge

Hey guys I need your bit help in Code Challenge

Problem: You want to repaint your house entirely for an upcoming occasion. The total area of your house is D units. There are a total of N workers. The ith worker has his available time Ti, hiring cost Xi and speed Yi. This means that he is available for hiring from time Ti and remains available ever since. Once available, you can hire him with cost Xi, after which he will start painting the house immediately, covering exactly Yi units of house with paint per time unit. You may or may not hire a worker and can also hire or fire him at any later point of time. However, no more than 1 worker can be painting the house at a given time.

Since you want the work to be done as fast as possible, figure out a way to hire the workers, such that your house gets painted at the earliest possible time, with minimum cost to spend for hiring workers.

Note: You can hire a previously hired worker without paying him again.


The first line of input contains two integers "N D", the number of workers and the area of your house respectively. The ith of the next N lines denotes the ith worker, and contains three integers "Ti Xi Yi", described in the statement.


Output one integer, the minimum cost that you can spend in order to get your house painted at the earliest.


1 ≤ N, T, X, Y ≤ 105 1 ≤ D ≤ 1011

Sample Input(Plaintext Link) 3 3 1 1 1 2 2 2 3 1 5 Sample Output(Plaintext Link) 3 Explanation We can hire the first worker at cost of 1 and second at cost of 2, to finish painting at the minimum time of exactly 2 time units.

my Solution

include <iostream>

include <string.h>

int n; using namespace std; int main() { int d,t,c,s; cin>>n; cin>>d; for(int i=0;i<n;i++) { cin>>t>>c>>s;

for(int i=0;i<n;i++)