{"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":"\u003cdiv class\u003d\"panel_content\"\u003e\n HDU’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.\n \u003cbr\u003e\n \u003cbr\u003e\n The 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\u003e\n Now 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\n\u003cbr\u003e\n现有n个教室在一条线上,这可以看作是一条数轴。每个教室都有一个坐标。现在小Q想在这些教室里建几家糖果店。\n总费用由两部分组成。在教室里建一个糖果店会有一些成本。对于每一个没有糖果店的教室P,那么P到P左侧离P最近的有糖果店的教室之间的距离也会包含在总费用中。很明显,如果教室里没有糖果店,那么教室左边一定有一家糖果店。\n现在小Q想知道如何以最小的成本建造糖果店。请写一个程序来帮助他。"}},{"title":"Input","value":{"format":"HTML","content":"The input contains several test cases, no more than 10 test cases.\n\u003cbr\u003e\nIn each test case, the first line contains an integer $n(1\\leq n\\leq 3000)$, denoting the number of the classrooms.\n\u003cbr\u003e\nIn 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\u003e\nThere are no two classrooms having same coordinate.\n\u003cbr\u003e\n输入包含几个测试用例,但不会超过10个。\n在每个测试用例中,第一行包含一个整数n(1≤n≤3000),表示教室的数量。\n在接下来的n行中,每一行包含两个整数xi,ci(-10^9≤xi,ci≤10^9),表示第i间教室的坐标以及在其中建造糖果店的成本。\n没有两个教室有相同的坐标。"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print a single line containing an integer, denoting the minimal cost.\n\u003cbr\u003e\n对于每个测试用例,打印单行包含一个整数,表示最小成本。"}},{"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\n1 2\n2 3\n3 4\n4\n1 7\n3 1\n5 10\n6 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\n11\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}