#include #include #include #include #include #include using namespace std; int a[100010] , b[100010]; int k[1010] , p[1010]; int kp[11][1010]; int dp[2010]; int main() { int n , m; while( scanf( "%d %d" , &n , &m ) != EOF ) { for( int i=0 ; i= maxp ) { printf( "-1\n" ); continue; } for( int D = 0 ; D <= maxb ; D++ ) { memset( dp , -1 , sizeof(dp) ); dp[0] = 0; int mx = 0; for( int i=0 ; i= 0 ) { for( int j=0 ; j dp[i] + k[j] ) { dp[nxt] = dp[i] + k[j]; mx = nxt; } } } for( int i=mx-1 ; i>0 ; i-- ) { if( dp[i] >= 0 ) dp[i] = min( dp[i] , dp[i+1] ); else dp[i] = dp[i+1]; } for( int i=0 ; i<=maxa ; i++ ) kp[D][i] = dp[i]; } long long ans = 0; for( int i=0 ; i