TestVita | Code Vita 2015 | round 2

TestVita

Problem:

TCS is working on a new project called "TestVita". There are N modules in the project. Each module (i) has completion time denoted in number of hours (Hi) and may depend on other modules. If Module x depends on Module y then one needs to complete y before x.

As Project manager, you are asked to deliver the project as early as possible.
Provide an estimation of amount of time required to complete the project.
Input Format:

First line contains T, number of test cases.

For each test case: 
  1. First line contains N, number of modules.
  2. Next N lines, each contain:
    • (i) Module ID
    • (Hi) Number of hours it takes to complete the module
    • (D) Set of module ids that i depends on - integers delimited by space.

Output Format:

Output the minimum number of hours required to deliver the project.

Constraints:

1. 1 <= T <= 10
2. 0 < N < 1000; number of modules
3. 0 < i <= N; module ID 
4. 0 < Hi < 60; number of hours it takes to complete the module i
5. 0 <= |D| < N; number of dependencies
6. 0 < Dk <= N; module ID of dependencies

Sample Input and Output

SNo.InputOutput
1
1
5
1 5 0
2 6 1
3 3 2
4 2 3
5 1 3

16

Program:

#include <stdio.h>
int main() {
int n,m[10],t[10],d[10],q,a,i,sum=0;
scanf("%d",&a);
for(q=1;q<=a;q++)
{
scanf("%d",&n);
for(i=0;i<n;i++)
    scanf("%d %d %d",&m[i],&t[i],&d[i]);
    for(i=0;i<n-1;i++)
    {
            if(d[i]==d[i+1])
            {
                if(t[i]<t[i+1])
                t[i]=0;
                else
                t[i+1]=0;
            }
    }
   for(i=0;i<n;i++)
   {
       sum=sum+t[i];
   }
    printf("%d",sum);
}
return 0;
}

Output:

1
5
1 5 0
2 6 1
3 3 2
4 2 3
5 1 3

16

You can also run it on an online IDEhttps://ide.geeksforgeeks.org/eTqOGzjCr5

Your feedback are welcomed! If you have any doubts you can contact me or comment below! Cheers!

 Related Link: Bank Compare

5 comments:

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...