Untitled diff

Created Diff never expires
1 removal
62 lines
1 addition
62 lines
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
using namespace std;
#define MOD 1000000007LL
#define MOD 1000000007LL
#define M 1
#define M 1
#define X first
#define X first
#define Y second
#define Y second


typedef long long ll;
typedef long long ll;
typedef pair< int, int >pii;
typedef pair< int, int >pii;
typedef pair< ll , ll >pll;
typedef pair< ll , ll >pll;


ll one = 1LL;
ll one = 1LL;


ll c[39];
ll c[39];
ll n;
ll n;


ll cst(ll msk)
ll cst(ll msk)
{
{
ll rt = 0;
ll rt = 0;
for (ll i = 0; i < 31; i++) {
for (ll i = 0; i < 31; i++) {
if (msk&(one<<i)) {
if (msk&(one<<i)) {
if (i < n) rt += c[i];
if (i < n) rt += c[i];
else rt += (c[n-1] << (i-n+1));
else rt += (c[n-1] << (i-n+1));
}
}
}
}
//cout << "cost for " << msk << " -> " << rt << endl;
//cout << "cost for " << msk << " -> " << rt << endl;
return rt;
return rt;
}
}


int main()
int main()
{
{
std::ios::sync_with_stdio(false);
std::ios::sync_with_stdio(false);


ll L;
ll L;


cin >> n >> L;
cin >> n >> L;




for (ll i = 0; i < n; i++) cin >> c[i];
for (ll i = 0; i < n; i++) cin >> c[i];


for (ll i = 1; i < n; i++) {
for (ll i = 1; i < n; i++) {
c[i] = min(c[i], c[i-1]*2);
c[i] = min(c[i], c[i-1]*2);
//cout << "c[" << i << "] = " << c[i] << endl;
//cout << "c[" << i << "] = " << c[i] << endl;
}
}


ll ans = cst(L);
ll ans = cst(L);


while (true) {
while (true) {
ll i;
ll i;
for (i = 0; (L&(one<<i))==0 ; i++);
for (i = 0; (L&(one<<i))==0 ; i++);
if (i > n) break;
if (i > 30) break;
ans = min(ans, cst(L));
ans = min(ans, cst(L));
for ( ; (L&(one<<i)); i++) {
for ( ; (L&(one<<i)); i++) {
L ^= (one<<i);
L ^= (one<<i);
}
}
L ^= (one<<i);
L ^= (one<<i);
}
}


cout << ans << endl;
cout << ans << endl;


return 0;
return 0;
}
}