LCC '21 Contest 2 J4 - Gaming

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Oscar is playing games throughout an entire course! In this course, there are N friends, and M snitches. Each friend will cover Oscar for a consecutive number of lessons, from a to b, inclusive. Each snitch will be next to Oscar for a consecutive number of lessons, from c to d, inclusive. Oscar is only able to play games during lessons when there is at least one friend covering him, and when no snitches are next to him. At times where there are friends and snitches or no friends and no snitches next to him, Oscar cannot play games.

Given that there are K lessons in this course numbered from 1 to K, can you determine how many lessons Oscar will play games for in total?

Input Specification

The first line will contain N (1 \leq N \leq 100), M (1 \leq M \leq 100), and K (1 \leq K \leq 10^3), the number of friends, snitches, and lessons in the course, respectively.

The next N lines will contain integers a_i and b_i (1 \leq a_i \leq b_i \leq K), the consecutive lessons where Oscar is covered for.

The next M lines will contain integers c_i and d_i (1 \leq c_i \leq d_i \leq K), the consecutive lessons where a snitch is near Oscar.

Output Specification

Output one integer, the total number of lessons that Oscar will play games for in total.

Sample Input 1

2 1 10
1 3
4 6
5 9

Sample Output 1

4

Sample Explanation

The first friend covers Oscar for the first 3 lessons. The second friend covers him from lesson 4 to 6, but there is a snitch that is near him from lesson 5 to 9, so he can only play during lesson 4. During lesson 10, since there is no friend covering him, Oscar cannot play games either. Thus, the answer is 4 as Oscar will play games from lesson 1 to lesson 4.


Comments

There are no comments at the moment.