Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruturaj-Godse authored Nov 29, 2020
1 parent cb4b94e commit 6edd3d2
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
# Covid-Crisis
# Covid-Crisis

<B>Problem Statement -</B><br>
ROOT2 Industries is a huge business firm. However, recently it has been hit hard by the fall of the market due to COVID - 19 and is almost on its way to bankruptcy. In order to prevent this the firm has decided to cut loose some of its departments.
The departments in the firm have a hierarchical structure (with the Head Office at the root). Each department can have one or more sub-departments but each sub-department will have only one super-department.
You have the details about the working costs and revenue generated by each department. The firm has to cut loose some of its departments, but if a department is cut loose, all its sub-departments are also dissolved, firing all the people working in them.
Any department can be dissolved only by a department which lies in the hierarchical path from the department to the head office.
Also a department can be dissolved by some other department only if the department (which is dissolving) has strictly better performance than the department being dissolved.

Performance of a department is determined by <i>(Revenue Generated - Working Costs)</i> of the department.

You have to write a program to find the departments which need to be fired and the corresponding department which will fire it in order to maximize the overall performance of the firm. If a department can be fired by multiple departments, output the department closest to it in the hierarchical structure.
If there are multiple answers, print the one that requires the minimum number of departments to be fired explicitly.

*All the departments that need to be fired are fired simultaneously.<br>
*Dissolve / Cut-loose / Fire all mean the same thing for the purpose of this question and are used interchangeably.

<b>Input -</b><br>
First line will contain a single integer n, number of departments in the ROOT2 firm. <br>
The next line contains n space-separated integers w<sub>1</sub>, w<sub>2 </sub>, …, w<sub>n </sub> representing the working costs of each department, where w<sub>i </sub> represents the working cost of the i<sup>th </sup> department. <br>
The next line contains n space-separated integers r<sub>1 </sub>, r<sub>2 </sub>, …, r<sub>n </sub> representing the revenue generated by each department, where r <sub> i</sub> represents the revenue generated by i<sup>th </sup> department.
<br>
The next n-1 lines contain 2 integers u and v, describing that department v is a sub-department of department u.

<b>Output -</b><br>
Print on a single line k - number of departments that need to be dissolved to maximize the performance of the firm.<br>
On each of the next k lines, print the number of the department that needs to be dissolved and the number of the department that dissolves it.

<b>Note </b> - Print these k lines in the ascending order sorted by the number of the department getting dissolved.
<br><br>

<b>Constraints - </b><br>
0 < n <= 1000<br>
0 <= wi, ri <= 100000<br>
1 <= u, v <= n<br>



<b>Sample Input 1-</b><br>
5<br>
100 400 50 200 10<br>
200 50 100 300 20<br>
1 2<br>
1 3<br>
2 4<br>
2 5<br>

<b>Sample Output 1-</b><br>
1<br>
2 1<br>
<br>

<b>Sample Input 2-</b><br>
7<br>
100 12 19 64 32 22 23<br>
93 97 40 24 29 58 57<br>
1 7<br>
7 6<br>
6 3<br>
6 5<br>
3 2<br>
1 4<br>

<b>Sample Output 2-</b><br>
2<br>
4 1<br>
5 6<br>


0 comments on commit 6edd3d2

Please sign in to comment.