{"trustable":false,"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":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n 姚佳强’s $n$ classrooms are on a line ,which can be considered as a number line. Each classroom has a coordinate. laksjdf按时打算离开东京发射点法大师傅several candy shops in these $n$ classrooms.\n \u003cbr\u003e\n \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.\n \u003cbr\u003e\n \u003cbr\u003eNow Little Q wants to know how to build the candy shops with the minimal cost. Please write a program to help him.\n \u003cbr\u003e\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains several test cases, no more than 10 test cases.\n\u003cbr\u003eIn each test case, the first line contains an integer $n(1\\leq n\\leq 3000)$, denoting the number of the classrooms.\n\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.\n\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 Input","value":{"format":"HTML","content":"\u003cpre\u003e3\n1 2\n2 3\n3 4\n4\n1 7\n3 1\n5 10\n6 1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e5\n11\u003c/pre\u003e"}}]}