using
System;
using
System.Collections.Generic;
class
Shop
{
public
long
Get(
int
position)
{
List<
long
> prices =
new
List<
long
> { 2, 4, 6 };
if
(position >= 0 && position < prices.Count)
{
return
prices[position];
}
else
{
return
-1;
}
}
}
class
Solution
{
private
Shop shop;
public
Solution(Shop s) {
this
.shop = s; }
private
long
Help(
int
q, Dictionary<
int
,
long
> m, Shop sp)
{
if
(m.ContainsKey(q))
return
m[q];
long
result = sp.Get(q - 1);
m[q] = result;
return
result;
}
public
long
Find(
int
n,
long
k)
{
Dictionary<
int
,
long
> m =
new
Dictionary<
int
,
long
>();
long
ans = 0;
ans += k / Help(n, m,
this
.shop);
k %= Help(n, m,
this
.shop);
int
l = 0, r = n;
while
(
true
)
{
l = 0;
while
(l + 1 < r)
{
int
mid = (l + r) / 2;
if
(Help(mid, m,
this
.shop) <= k)
l = mid;
else
r = mid;
}
if
(l == 0)
break
;
ans += k / Help(l, m,
this
.shop);
k %= Help(l, m,
this
.shop);
}
return
ans;
}
}
class
MainClass
{
public
static
void
Main(
string
[] args)
{
Shop shop =
new
Shop();
Solution solution =
new
Solution(shop);
int
n = 3;
long
k = 5;
long
result = solution.Find(n, k);
Console.WriteLine(
"Maximum number of chocolates Geek can enjoy: "
+ result);
}
}