CF856F.To Play or not to Play

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya and Petya are playing an online game. As most online games, it has hero progress system that allows players to gain experience that make their heroes stronger. Of course, Vasya would like to get as many experience points as possible. After careful study of experience points allocation, he found out that if he plays the game alone, he gets one experience point each second. However, if two players are playing together, and their current experience values differ by at most CC points, they can boost their progress, and each of them gets 2 experience points each second.

Since Vasya and Petya are middle school students, their parents don't allow them to play all the day around. Each of the friends has his own schedule: Vasya can only play during intervals [a1;b1],[a2;b2],...,[an;bn][a_{1};b_{1}],[a_{2};b_{2}],...,[a_{n};b_{n}] , and Petya can only play during intervals [c1;d1],[c2;d2],...,[cm;dm][c_{1};d_{1}],[c_{2};d_{2}],...,[c_{m};d_{m}] . All time periods are given in seconds from the current moment. Vasya is good in math, so he has noticed that sometimes it can be profitable not to play alone, because experience difference could become too big, and progress would not be boosted even when played together.

Now they would like to create such schedule of playing that Vasya's final experience was greatest possible. The current players experience is the same. Petya is not so concerned about his experience, so he is ready to cooperate and play when needed to maximize Vasya's experience.

输入格式

The first line of input data contains integers nn , mm and CC — the number of intervals when Vasya can play, the number of intervals when Petya can play, and the maximal difference in experience level when playing together still gives a progress boost ( 1<=n,m<=21051<=n,m<=2·10^{5} , 0<=C<=10180<=C<=10^{18} ).

The following nn lines contain two integers each: ai,bia_{i},b_{i} — intervals when Vasya can play ( 0<=a_{i}<b_{i}<=10^{18} , b_{i}<a_{i+1} ).

The following mm lines contain two integers each: ci,dic_{i},d_{i} — intervals when Petya can play ( 0<=c_{i}<d_{i}<=10^{18} , d_{i}<c_{i+1} ).

输出格式

Output one integer — the maximal experience that Vasya can have in the end, if both players try to maximize this value.

输入输出样例

  • 输入#1

    2 1 5
    1 7
    10 20
    10 20
    

    输出#1

    25
    
  • 输入#2

    1 2 5
    0 100
    20 60
    85 90
    

    输出#2

    125
    
首页