# IPCTRAIN - Editorial

#PROBLEM LINK:
[Practice][1]
[Contest][2]
**Author:** [Admin2][3]
**Primary Tester:** [Misha Chorniy][4]
**Editorialist:** [Hussain Kara Fallah][6]
#DIFFICULTY:
Easy
#PREREQUISITES:
Greedy,Heap
#PROBLEM:
You have an upcoming camp. There are N trainers. The camp runs for **D** days.Each day,there can be at most one lecture. The **i<sup>th</sup>** trainer arrives on day **D<sub>i</sub>** and then stays till the end of the camp. He also wants to teach exactly **T<sub>i</sub>** lectures. For each lecture that a trainer was not able to teach,his sadness level will be increased by **S<sub>i</sub>.**
You are the main organizer of the contest. You want to find minimum total sadness of the trainers.
#EXPLANATION:
Let's assign our trainers starting from the first day of the camp. At each day adding arriving trainers to our set of trainers.
Each day should be assigned to only **one** trainer, it's obvious that we should assign the trainer with maximum sadness to this lecture, so our set (container) should be a heap sorting trainers by their sadness value. In fact we should know also the number of days each lecturer wants to serve in, so we take the lecturer with maximum sadness from our heap and decrease his demand by 1. In case he still has lectures he would like to do, we keep him in the heap, otherwise we just pop him out.
After finishing all days, some teachers may have some remaining lectures they wanted to teach but we couldn't find such days for them. Let's denote the number of lectures the **i<sup>th</sup>** trainer couldn't teach by **rem<sub>i</sub>** So our answer would be :
$answer = \sum_{i=1}^{i=N} rem_i * S_i$
#AUTHOR'S AND TESTER'S SOLUTIONS:
**AUTHOR's solution**: Will be found [here][8]
**TESTER's solution**: Will be found [here][9]
**EDITORIALIST's solution**: Will be found [here][10]
[1]:https://www.codechef.com/JULY17/problems/IPCTRAIN
[2]:https://www.codechef.com/problems/IPCTRAIN
[3]:https://www.codechef.com/users/admin2
[4]:https://www.codechef.com/users/mgch
[6]:https://www.codechef.com/users/deadwing97
[7]:https://www.eecis.udel.edu/~breech/progteam/stringstream.html
~~[8]:https://s3.amazonaws.com/codechef_shared/download/Solutions/JULY17/Setter/IPCTRAIN.java
[9]:https://s3.amazonaws.com/codechef_shared/download/Solutions/JULY17/Tester/IPCTRAIN.java
[10]:https://s3.amazonaws.com/codechef_shared/download/Solutions/JULY17/Editorialist/IPCTRAIN.java~~[8]:https://s3.amazonaws.com/codechef_shared/download/Solutions/JULY17/Setter/IPCTRAIN.cpp
[9]:https://s3.amazonaws.com/codechef_shared/download/Solutions/JULY17/Tester/IPCTRAIN.cpp
[10]:https://s3.amazonaws.com/codechef_shared/download/Solutions/JULY17/Editorialist/IPCTRAIN.cpp