#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
using namespace std;
class MulticoreProcessing {
public :
long long fastestTime( long long N, int M, vector < int > speed, vector < int > cores) {
long long ret = ( 1LL << 60 ) , MM = M;
for ( int i = 0 ; i < speed.size ( ) ; i++ ) {
long long L = 1 , R = ( 1LL << 30 ) , U, maxn = 0 ;
for ( int j = 0 ; j < 34 ; j++ ) {
U = ( L + R) / 2 ;
if ( ( N / ( U* ( U + 1 ) ) ) < MM) { R = U; }
else { L = U; maxn = max( maxn, U) ; }
}
long long I = min( 1LL * cores[ i] , max( 1LL, U) ) ;
long long J = ( ( N - 1 ) / ( 1LL * speed[ i] * I) ) + 1LL; J + = ( I - 1 ) * MM;
ret = min( ret, J) ;
}
return ret;
}
} ;
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBNdWx0aWNvcmVQcm9jZXNzaW5nIHsKcHVibGljOgoJbG9uZyBsb25nIGZhc3Rlc3RUaW1lKGxvbmcgbG9uZyBOLCBpbnQgTSwgdmVjdG9yIDxpbnQ+IHNwZWVkLCB2ZWN0b3IgPGludD4gY29yZXMpIHsKCQlsb25nIGxvbmcgcmV0ID0gKDFMTCA8PCA2MCksIE1NID0gTTsKCQlmb3IgKGludCBpID0gMDsgaSA8IHNwZWVkLnNpemUoKTsgaSsrKSB7CgkJCWxvbmcgbG9uZyBMID0gMSwgUiA9ICgxTEwgPDwgMzApLCBVLCBtYXhuID0gMDsKCQkJZm9yIChpbnQgaiA9IDA7IGogPCAzNDsgaisrKSB7CgkJCQlVID0gKEwgKyBSKSAvIDI7CgkJCQlpZiAoKE4g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