#include #include #include #include #include using namespace std; #define MS(m,z) memset(m,z,sizeof(m)) typedef unsigned U; typedef pair P; typedef long long ll; void inp(); int main(){ #ifdef XS freopen("1004.in","r",stdin); #endif while(1)inp(); return 0; } const int J=1e3+10,K=10+5; int dp[2][J][K]; const int inf=0x7fffffff,N=1e5+10;; P mon[N]; void inp(){ int n,m;if(scanf("%d%d",&n,&m)==EOF)exit(0); int i,j,k,ki,pi; for(i = 0;i<2;i++)for(j =0 ;j=pi){ dp[f][j][k]=dp[!f][j][k]; } else { tmp = j-(pi-k); if(tmp<0)tmp=0; dp[f][j][k]=min(dp[f][tmp][k]+ki,dp[!f][j][k]); } } } } int a,b; ll ans=0; for(i = 0;i