{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eIn a town divided into a grid with \u003cvar\u003e\\(N\\)\u003c/var\u003e rows and \u003cvar\u003e\\(10^9\\)\u003c/var\u003e columns, there are \u003cvar\u003e\\(N\\)\u003c/var\u003e walls, numbered \u003cvar\u003e\\(1\\)\u003c/var\u003e to \u003cvar\u003e\\(N\\)\u003c/var\u003e.\u003cbr\u003e\r\nWall \u003cvar\u003e\\(i\\)\u003c/var\u003e ranges from the \u003cvar\u003e\\(L_i\\)\u003c/var\u003e-th column to the \u003cvar\u003e\\(R_i\\)\u003c/var\u003e-th column from the left in the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th row from the top. (See also the figure at Sample Input and Output \u003cvar\u003e\\(1\\)\u003c/var\u003e.)\u003c/p\u003e\r\n\u003cp\u003eTakahashi has decided to destroy all \u003cvar\u003e\\(N\\)\u003c/var\u003e walls.\u003cbr\u003e\r\nWith his superhuman strength, his one punch can damage consecutive \u003cvar\u003e\\(D\\)\u003c/var\u003e columns at once.\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eMore formally, he can choose an \u003cstrong\u003einteger\u003c/strong\u003e \u003cvar\u003e\\(x\\)\u003c/var\u003e between \u003cvar\u003e\\(1\\)\u003c/var\u003e and \u003cvar\u003e\\(10^9 - D + 1\\)\u003c/var\u003e (inclusive) to damage all walls that exist (or partly exist) in the \u003cvar\u003e\\(x\\)\u003c/var\u003e-th through \u003cvar\u003e\\((x + D - 1)\\)\u003c/var\u003e-th columns and are not yet destroyed.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eWhen a part of a wall is damaged, that whole wall will be destroyed by the impact of the punch.\u003cbr\u003e\r\n(See also the figure at Sample Input and Output \u003cvar\u003e\\(1\\)\u003c/var\u003e.)\u003c/p\u003e\r\n\u003cp\u003eAt least how many times does Takahashi need to punch to destroy all walls?\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq N \\leq 2 \\times 10^5\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq D \\leq 10^9\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq L_i \\leq R_i \\leq 10^9\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003eAll values in input are integers.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e \u003cvar\u003e\\(D\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(L_1\\)\u003c/var\u003e \u003cvar\u003e\\(R_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(L_2\\)\u003c/var\u003e \u003cvar\u003e\\(R_2\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(\\vdots\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(L_N\\)\u003c/var\u003e \u003cvar\u003e\\(R_N\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint the minimum number of punches needed to destroy all walls.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","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 3\r\n1 2\r\n4 7\r\n5 9\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eThe figure below describes the arrangements of walls in Sample Input \u003cvar\u003e\\(1\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003e\u003cimg alt\u003d\"image\" src\u003d\"CDN_BASE_URL/eca3af62ca98e5f656a8790f8c5d3820?v\u003d1726122225\"\u003e\u003c/p\u003e\r\n\u003cp\u003eHe can destroy all walls with two punches, such as the following. (Below, \u003cvar\u003e\\(\\lbrack a, b \\rbrack\\)\u003c/var\u003e denotes the range from the \u003cvar\u003e\\(a\\)\u003c/var\u003e-th through \u003cvar\u003e\\(b\\)\u003c/var\u003e-th columns.)\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eFirst, punch \u003cvar\u003e\\(\\lbrack 2, 4 \\rbrack\\)\u003c/var\u003e. The walls existing in \u003cvar\u003e\\(\\lbrack 2, 4 \\rbrack\\)\u003c/var\u003e ― Walls \u003cvar\u003e\\(1\\)\u003c/var\u003e and \u003cvar\u003e\\(2\\)\u003c/var\u003e ― are damaged and destroyed.\u003c/li\u003e\r\n\u003cli\u003eSecond, punch \u003cvar\u003e\\(\\lbrack 5, 7 \\rbrack\\)\u003c/var\u003e. The wall existing in \u003cvar\u003e\\(\\lbrack 5, 7 \\rbrack\\)\u003c/var\u003e ― Wall \u003cvar\u003e\\(3\\)\u003c/var\u003e ― is damaged and destroyed.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eIt is also possible to destroy all walls with two punches in this way:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eFirst, punch \u003cvar\u003e\\(\\lbrack 7, 9 \\rbrack\\)\u003c/var\u003e to destroy Walls \u003cvar\u003e\\(2\\)\u003c/var\u003e and \u003cvar\u003e\\(3\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003eSecond, punch \u003cvar\u003e\\(\\lbrack 1, 3 \\rbrack\\)\u003c/var\u003e to destroy Wall \u003cvar\u003e\\(1\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","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 3\r\n1 2\r\n4 7\r\n4 9\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eThe difference from Sample Input/Output \u003cvar\u003e\\(1\\)\u003c/var\u003e is that Wall \u003cvar\u003e\\(3\\)\u003c/var\u003e now covers \u003cvar\u003e\\(\\lbrack 4, 9 \\rbrack\\)\u003c/var\u003e, not \u003cvar\u003e\\(\\lbrack 5, 9 \\rbrack\\)\u003c/var\u003e.\u003cbr\u003e\r\nIn this case, he can punch \u003cvar\u003e\\(\\lbrack 2, 4 \\rbrack\\)\u003c/var\u003e to destroy all walls with one punch.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 3","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\u003e5 2\r\n1 100\r\n1 1000000000\r\n101 1000\r\n9982 44353\r\n1000000000 1000000000\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\u003c/section\u003e\r\n"}}]}