{"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":"MD","content":"LYD正在准备明天的定向越野期末考试。考试内容如下:老师在校园内一共放置了 4 个打卡点,,分别用 $p_1$、$p_2$、$p_3$ 和 $p_4$ 表示。考生都从 $p_2$ 打卡然后出发,每次只能从 $p_i$ 跑向 $p_{i-1}$ 或 $p_{i+1}$ 并打卡(可从 $p_1$ 跑到 $p_4$,反之亦然),最后再回到 $p_2$ 作为终点。考核标准为考生的有效跑步距离超过 $k$ 所花费的时间,其中,当考生从最后一次打卡点 $p_i$ 处开始到下一个目的地并打卡时,这时两打卡点的距离被累加记入有效距离中。\nLYD为了花费尽可能少的时间达到考核要求,他希望规划出一条路线,使得有效跑步距离超过 $k$ 且尽可能小,你能帮帮他吗?"}},{"title":"Input","value":{"format":"MD","content":"第一行一个整数代表数据组数,保证不超过 15 组。\n每组数据包含 5 个整数 $k,d_{1,2},d_{2,3},d_{3,4},d_{4,1}$($1 \\le k \\le 10^{18}$,$1\\le d_{i,j}\\le 30000$),$d_{i,j}$ 代表打卡点 $p_i$ 和 $p_j$ 之间的距离。"}},{"title":"Output","value":{"format":"MD","content":"每组数据输出一个整数代表满足考核要求的最短距离。"}},{"title":"Sample#1","value":{"format":"MD","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\u003e\u003cpre\u003e1\n1001 200 250 105 355\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\u003cpre\u003e1110\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"Sample#2","value":{"format":"MD","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\u003e\u003cpre\u003e1\n2000 600 650 535 380\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\u003cpre\u003e2165\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}