#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef long double LD; typedef vector VI; typedef pair PII; const LD eps=1e-9; const LD PI=atan2((LD)0,(LD)-1); const LL MOD=1000000007; const int INF=1<<30; const int ARR_INF=1<<6; const int MAXN=100005; const int MAXM=1005; int n, m; int a[MAXN], b[MAXN]; int k[MAXM], p[MAXM]; int dmg[MAXM]; int dp[2*MAXM][11]; void get_dmg() { memset(dmg, -1, sizeof(dmg)); for(int i=0; i k[i]) dmg[p[i]] = k[i]; } m = 0; for(int i=0; i dp[i-dm][j] + k[l])) min_k = dp[i-dm][j] + k[l]; } dp[i][j] = min_k; } int set_k = dp[2*MAXM-1][j]; for(int i=2*MAXM-2; i>=0; i--) { if(set_k == -1) set_k = dp[i][j]; else { if(dp[i][j] != -1) set_k = min(dp[i][j], set_k); } dp[i][j] = set_k; } } } LL cal_ans() { LL ans = 0; for(int i=0; i