#K67597. Minimize Fines in Projects
Minimize Fines in Projects
Minimize Fines in Projects
You are given P projects. Each project consists of a series of tasks. Each task has a duration, a deadline, and a fine incurred if the task is completed after its deadline.
For each project, tasks are executed sequentially in the order provided. When executing a project, the current time starts at 0. For each task, add its duration to the current time. If the current time is greater than the task's deadline, you incur the corresponding fine.
Your task is to compute the total minimum fine incurred by processing all the projects, assuming the tasks in each project must be executed in the given order.
Mathematically, for each project, let \( t_i \) be the duration of the \( i^{th} \) task and \( d_i \) its deadline. Define \( T_i = \sum_{j=1}^{i} t_j \). If \( T_i > d_i \), then fine \( f_i \) is incurred for that task. Sum the fines for all tasks across all projects to get the answer.
inputFormat
The input is read from standard input (stdin) and has the following format:
P N1 times1 (N1 integers separated by spaces) deadlines1 (N1 integers) fines1 (N1 integers) N2 times2 deadlines2 fines2 ... NP timesP deadlinesP finesP
Here, P denotes the number of projects. For each project, the first line contains an integer N (the number of tasks). The next three lines each contain N space-separated integers representing the durations, deadlines, and fines respectively. If P is 0, there are no projects and the input contains only the integer 0.
outputFormat
Output to standard output (stdout) a single integer representing the total fine incurred after processing all the projects.
## sample1
2
2 3
3 10
10 20
0