Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Oh No! Classes!

By mehdi_ · Limits 1s, 512 MB

You will be given three pairs of integers, which denotes the starting and ending time in seconds of three classes.

The task is very simple. You have to assign three classrooms for the classes and find the total class time. Class time is when at least one class is running.


The first line will contain a positive integer T (1 ≤ T ≤ 100), denoting the number of test cases.

Each of the next T lines will contain 6 space separated positive integers denoting a1, b1, a2, b2, a3, b3 (0 ≤ a1, b1, a2, b2, a3, b3 ≤ 106).

Integers ai and bi are the starting and finishing time respectively of the i'th class.


For each test case print the time required.


1 2 3 4 5 6

Here the first class is from 1 to 2 inclusive, so the class time is 2. The second class is from 3 to 4 inclusive, so the class time is 2 and it is the same for the third one.



58% Solution Ratio

AashiqEarliest, Jan '17

oneoff.AqPpVLnpe3Fastest, 0.0s

Nasif_44thLightest, 0 B

bokaifShortest, 133B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.