#Lutece2039. 心的距离
心的距离
Migrated from Lutece 2039 心的距离
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
通过坡道上的交谈,子辉
知道了她叫Sakura
,如樱花一样美丽的名字。而且还是同一个班上的。但在子辉
与Sakura
的班级座位之间却隔着有位同学,子辉
想要支走中间这位同学,从而和Sakura
拉近心的距离。包括子辉
和Sakura
在内一共个人(子辉
编号为,Sakura
编号为),从左到右第个人的任性指数为。支走第个人时,设第个人左边最近的还没走的人(可以是子辉
或Sakura
)编号为,右边为,需付出 的精力。子辉
想要知道最少付出多少精力,可以支走中间所有的同学,拉近与Sakura
的距离,这就需要机智地安排顺序了。
Input
第一行一个整数 (). 第二行 个用空格分隔的整数 ,,...,, 保证 .
Output
输出最少需要付出的精力
Samples
2
10 100 5 50
7500
Resources
2018 UESTC Training for Dynamic Programming