College Life 2 Codechef Solution

Chef has just started watching Game of Thrones, and he wants to first calculate the exact time (in minutes) that it’ll take him to complete the series.

The series has SS seasons, and the ithith season has EiEi episodes, each of which are Li,1,Li,2,…,Li,EiLi,1,Li,2,…,Li,Ei minutes long. Note that these Li,jLi,j include the duration of the beginning intro song in each episode. The streaming service that he uses, allows Chef to skip the intro song. The intro song changes slightly each season, and so he wants to watch the intro song in the first episode of each season, but he’ll skip it in all other episodes of that season (yes, we know, a sacrilege!). You know that the intro song lasts for QiQi minutes in the ithith season.

Find the total time in minutes, that he has to watch.

Input:

• First line will contain a single integer, TT, denoting the number of testcases. Then the testcases follow.
• The first line of each testcase will contain a single integer SS, denoting the total number of seasons.
• The second line contains SS space separated integers, Q1,Q2,…,QSQ1,Q2,…,QS, where QiQi denotes the duration of the intro song in the ithith season.
• The ithith of the next SS lines contains Ei+1Ei+1 space separated integers, where the first integer is EiEi, denoting the number of episodes in the ithith season. That is followed by the duration of each of the EiEi episodes, Li,1,Li,2,…,Li,EiLi,1,Li,2,…,Li,Ei.

Output:

For each testcase, output the answer in a single line.

Constraints

• 1≤T≤51≤T≤5
• 1≤S≤1051≤S≤105
• 2≤Li,j≤1052≤Li,j≤105
• 1≤Ei1≤Ei
• Sum of all EiEi in a single testcase is at most 105105
• 1≤Qi<Li,j1≤Qi<Li,j, for all valid jj.

1
2
1 2
1 2
2 3 4

7

Explanation:

1 in the beginning denotes there is only 11 test case.

Testcase 1:

There are 22 seasons. The intro song in each of the first season episodes lasts for 11 minute, and the intro song in the second season episodes lasts for 22 minutes each.

For the first season, since there is only 11 episode, Chef will be watching it completely – 22 minutes.

For the second season, Chef will be watching the first episode completely (33 minutes) and will skip the intro song of the second episode (4−2=24−2=2 minutes).

So, the total time spent is 2+(3+(4−2))=72+(3+(4−2))=7 minutes.

2
1
10
5 11 11 11 11 11
5
10 10 10 10 10
1 11
1 11
1 11
1 11
1 11

15
55

Explanation:

2 in the beginning denotes there are 22 test cases.

Testcase 1:

There is only 11 season having intro song for 1010 minutes.

Chef will have to watch the entire first episode including the intro song and will be skipping the same in further seasons.

So, the total time spent is (11+(11−10)∗4)=15(11+(11−10)∗4)=15 minutes.

Testcase 2:

There are total 55 seasons. The intro song in every season lasts for 1010 minutes.

For each of the five seasons, since there is only 11 episode, Chef will be watching all of them completely – 1111 minutes each.

So, the total time spent is 11∗5=5511∗5=55 minutes.

College Life 2   – CodeChef Solution in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0)
{
int sea = in.nextInt();
int ins[] = new int[sea];
for (int i = 0; i < sea; i++) {
ins[i] = in.nextInt();
}
int j = 0;
long ts = 0;
while (j < sea) {
int ep = in.nextInt();

for (int i = 0; i < ep; i++) {
int a = in.nextInt();
if (i == 0 )
ts+=a;
else
ts+= (a-ins[j]);
}

j++;
}
System.out.println(ts);
}
}catch (Exception e){
return;
}
}
}

College Life 2  – CodeChef Solution in CPP

#include <bits/stdc++.h>
using namespace std;

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define maxii INT_MAX
#define minii INT_MIN
#define mod 1000000007

int main()
{
FASTIO;
int t;
cin>>t;
while(t--){
ll n,k;
cin>>n;
vector <int> v;
for(int i=0;i<n;i++){
cin>>k;
v.push_back(k);
}
ll sum=0,q,x,j=0;
while(j<n){
cin>>q;
for(int i=0;i<q;i++){
cin>>x;
sum += (x-v[j]);
}
sum += v[j];
j++;
}
cout<<sum<<"\n";
}

return 0;
}

College Life 2  -CodeChef Solution in Python

cases = int(input())
while cases>0:
totalTime = 0
season = int(input())
introTime = list(map(int, input().split()))

for i in range(1,season+1):
episodesTime = list(map(int, input().split()))
for j in range(len(episodesTime)):
if j > 1:
totalTime = totalTime + episodesTime[j] - introTime[i-1]
elif j == 1:
totalTime = totalTime + episodesTime[j]
print(totalTime)
cases= cases-1

Disclaimer: The above Problem (College Life 2) is generated by CodeChef but the solution is provided by Codeworld19.This tutorial is only for Educational and Learning purpose.