Prochur Chhuti Lagbe (প্রচুর ছুটি লাগবে)

oorpib 7th CPU CSE Programming C...
Limits 1s, 512 MB

Nibir is currently working as a software engineer. He has been continuously working for the past few weeks because of work pressure. He is feeling a little bit tired. So, he is thinking about taking leaves for a few days. He wants to request leave for one or more days. He will not make more than one leave request on a single day. But all of his leaves may not be accepted by the authorities.

Why would they reject those leave requests?

Well, if the current requested leave days overlap with previously accepted leave days, the authorities will reject the current request. Otherwise, they will accept the current request, and these currently accepted leave days will be used to make decisions on future requests.

Now, how would the currently requested days overlap?
If the current requested day contains at least one day that exists in previously requested days.

Nibir wants to know the number of total accepted leave days.


Input will consist of N (N<=1000). N represents the number of previously accepted leaves that are valid.
Next, N line will contain X & Y in each line, (1 <= X <= Y<=10000).
X is the leave start day, end Y is the leave end day.

The next line will consist of Q (Q<=1000). Q represents the number of the latest requested leave.
Next Q line will contain A & B in each line (1 <= A <= B <=10000).
A is the leave start day, end B is the leave end day.


You have to print the total accepted leave days Nibir can have with the current Q request.


1 3
4 7
15 20
8 10
9 10
7 10

Here the only accepted leave day is 8-10. Hence total accepted leave days is 3.


Login to submit.


63% Solution Ratio
akash01Earliest, 1M ago
MR.Jukerburg11Fastest, 0.0s
md_jakariyaLightest, 5.7 MB
md_jakariyaShortest, 586B
Toph uses cookies. By continuing you agree to our Cookie Policy.