{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eHDU’s $n$ classrooms are on a line ,which can be considered as a number line. Each classroom has a coordinate. Now Little Q wants to build several candy shops in these $n$ classrooms.\u003cbr\u003e\u003cbr\u003eThe total cost consists of two parts. Building a candy shop at classroom $i$ would have some cost $c_i$. For every classroom $P$ without any candy shop, then the distance between $P$ and the rightmost classroom with a candy shop on $P$\u0027s left side would be included in the cost too. Obviously, if there is a classroom without any candy shop, there must be a candy shop on its left side.\u003cbr\u003e\u003cbr\u003eNow Little Q wants to know how to build the candy shops with the minimal cost. Please write a program to help him.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains several test cases, no more than 10 test cases.\u003cbr\u003eIn each test case, the first line contains an integer $n(1\\leq n\\leq 3000)$, denoting the number of the classrooms.\u003cbr\u003eIn the following $n$ lines, each line contains two integers $x_i,c_i(-10^9\\leq x_i,c_i\\leq 10^9)$, denoting the coordinate of the $i$-th classroom and the cost of building a candy shop in it.\u003cbr\u003eThere are no two classrooms having same coordinate."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print a single line containing an integer, denoting the minimal cost."}},{"title":"Sample","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\r\n1 2\r\n2 3\r\n3 4\r\n4\r\n1 7\r\n3 1\r\n5 10\r\n6 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n11\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}