#include using namespace std; const int maxn=100005; const int maxm=1005; const long long inf=0x3f3f3f3f3f3f3f3f; int n,m,a[maxn],b[maxn],K[maxm],p[maxm],dp[maxm<<1][11]; int main() { while (scanf("%d%d",&n,&m)==2) { for (int i=0;ik) for (int j=1;j<=2000;++j) dp[j][k]=min(dp[j][k],K[i]+dp[max(0,j-p[i]+k)][k]); long long res=0; for (int i=0;i=inf?-1:res); } return 0; }