/* * @Author: mengdaoshizhongxinyang * @Date: 2020-11-01 10:56:21 * @Description: */ #include #include #include #include #include #include using namespace std; int main(){ int n,m; int dp[1005][11]; while(cin>>n){ long long ans=0; for(int i=0;i<11;i++){ for(int j=0;j<1005;j++){ dp[j][i]=INT_MAX; } } for(int i=0;i<11;i++){ dp[0][i]=0; } int a[100005]; int b[100005]; int mb=0; cin>>m; int k[1005]; int p[1005]; int mp=0; for(int i=0;i=mp){ cout<<-1<=a[i]){ ans+=dp[a[i]][b[i]]; }else{ for(int j=md[b[i]]+1;j<=a[i];j++){ for(int s=0;sb[i]){ if(j>=p[s]-b[i]){ dp[j][b[i]]=min(dp[j-p[s]+b[i]][b[i]]+k[s],dp[j][b[i]]); }else{ dp[j][b[i]]=min(dp[0][b[i]]+k[s],dp[j][b[i]]); } } } } md[b[i]]=a[i]; ans+=dp[a[i]][b[i]]; } } cout<