{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"epigraph\"\u003e\u003cdiv class\u003d\"epigraph-text\"\u003e\u003cspan class\u003d\"tex-font-style-it\"\u003eLife is a balance of holding on and letting go.\u003c/span\u003e\u003c/div\u003e\u003cdiv class\u003d\"epigraph-source\"\u003e— Molana Jalaluddin Rumi, \u003cspan class\u003d\"tex-font-style-it\"\u003eMake Yourself Free\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-it\"\u003eRN\u003c/span\u003e is playing a music game called \u003cspan class\u003d\"tex-font-style-tt\"\u003e\"Mu5Ed4sH\"\u003c/span\u003e on her computer.\u003c/p\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-it\"\u003eHold\u003c/span\u003e is a type of note with a time range $$$[l_i, r_i]$$$, and you need to keep one finger on it within the time range.\u003c/p\u003e\u003cp\u003eTo simplify the statement, let\u0027s assume that \u003cspan class\u003d\"tex-font-style-it\"\u003eHold\u003c/span\u003e is the only type of note in the game.\u003c/p\u003e\u003cp\u003eIn this game, the notes will appear on two tracks, forming two sequences of time ranges $$$s$$$ and $$$t$$$. If two \u003cspan class\u003d\"tex-font-style-it\"\u003eHolds\u003c/span\u003e appear at the same time, then you need to use two fingers together.\u003c/p\u003e\u003cp\u003eHowever, if you use two fingers together for $$$t$$$ seconds, then you will lose exactly $$$t$$$ energy.\u003c/p\u003e\u003cp\u003eGiven the initial energy $$$E$$$ you have, determine whether the energy is enough to play the entire game. If it is enough, output the energy you will have left.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains two integers $$$n$$$, $$$m$$$, $$$E$$$ $$$(1 \\leq n + m \\leq 10 ^ 5, \\min(n, m) \\geq 1, 0 \\leq E \\leq 10 ^ 9)$$$, denoting the number of time ranges in sequence $$$s$$$ and $$$t$$$, and the initial energy you have.\u003c/p\u003e\u003cp\u003eThe $$$i$$$-th of the next $$$n$$$ lines contains two integers $$${l_s}_i$$$, $$${r_s}_i$$$ $$$(0 \\leq {l_s}_i \u0026lt; {r_s}_i \\leq 10 ^ 9)$$$, denoting the time range of the $$$i$$$-th \u003cspan class\u003d\"tex-font-style-it\"\u003eHold\u003c/span\u003e in sequence $$$s$$$.\u003c/p\u003e\u003cp\u003eThe $$$i$$$-th of the next $$$m$$$ lines contains two integers $$${l_t}_i$$$, $$${r_t}_i$$$ $$$(0 \\leq {l_t}_i \u0026lt; {r_t}_i \\leq 10 ^ 9)$$$, denoting the time range of the $$$i$$$-th \u003cspan class\u003d\"tex-font-style-it\"\u003eHold\u003c/span\u003e in sequence $$$t$$$.\u003c/p\u003e\u003cp\u003eIt\u0027s guaranteed that \u003cspan class\u003d\"tex-font-style-bf\"\u003eno\u003c/span\u003e two time ranges will \u003cspan class\u003d\"tex-font-style-bf\"\u003eoverlap\u003c/span\u003e in the \u003cspan class\u003d\"tex-font-style-bf\"\u003esame sequence\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eIf the energy is not enough, print $$$-1$$$; Otherwise, print a single integer $$$x$$$, denoting the energy you will have left.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 2 616\n5 7\n0 4\n8 9\n2 6\n7 10\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e612\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1 1 998244353\n0 1000000000\n0 1000000000\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first test case, there are $$$3$$$ time ranges in the first track and $$$2$$$ time ranges in the second track.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/cf7370f749e13087274687b32c239d56?v\u003d1726273189\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\" width\u003d\"720px\"\u003e \u003cspan class\u003d\"tex-font-size-small\"\u003eFigure of Test Case $$$1$$$\u003c/span\u003e \u003c/center\u003e\u003cp\u003eAs the figure shows, during $$$[2, 4]$$$, $$$[5, 6]$$$, $$$[8, 9]$$$, you need to use two fingers. And you will lose $$$(4 - 2) + (6 - 5) + (9 - 8) \u003d 4$$$ energy.\u003c/p\u003e\u003cp\u003eIt can be shown that the energy is enough, and the energy you will have left is $$$616 - 4 \u003d 612$$$.\u003c/p\u003e"}}]}