Video summary
The speaker begins the session by attempting to solve a competitive programming problem involving two characters, Little B and Little K, who take turns digging for treasure buried at varying depths. The rules state that on odd-numbered days, Little B digs $x$ meters while on even-numbered days, Little K digs $y$ meters, with both switching roles each day. The goal is to determine if the total depth dug exceeds 8.5 meters before a specific condition related to who finds it first is met; specifically, the speaker notes that if Little B does not dig up the treasure first, they should output "yes," otherwise "no." This setup creates an alternating sequence of digging depths where the cumulative sum must be carefully tracked against the threshold value.
As the problem-solving process unfolds, the speaker struggles with implementing the logic to handle this alternating pattern efficiently without simply simulating every single day step-by-step. They explore using modular arithmetic and binary search as potential solutions but quickly realize that a direct simulation or simple modulo operation is insufficient because it does not account for who made the final move when the threshold is crossed. The speaker attempts various mathematical approaches, such as calculating how many full cycles of $(x+y)$ fit into the total distance and then analyzing the remainder to see if $B$'s turn comes next in that partial cycle. They encounter difficulties with edge cases where subtracting distances incorrectly leads to overshooting or undershooting the target depth, causing their code logic to fail repeatedly during testing.
Eventually, through trial and error and some frustration about losing rating points on a difficult problem, the speaker refines their approach by realizing they must prioritize subtracting $y$ before $x$ when adjusting for an overshot total distance in their simulation loop. They identify that there are specific scenarios based on whether one day's digging amount is greater than the other, leading to different patterns of how many times each person digs within a given range. Despite finding the problem quite hard and admitting they might switch to an easier problem or stop for the night due to fatigue, the speaker successfully attempts the logic required to determine if Little B finds the treasure first by carefully managing the subtraction order in their conditional statements before concluding the video with plans to continue grinding on similar problems tomorrow.
Read the full video transcript
I haven't done this in a long time
guys maybe we'll try to go to green
again all right uh let's
see is it recording oh it is
okay okay little be and his a friend now
we dig up his treasure it is 1:30 a.m.
so I don't think my brain is not really
working that much so um but I didn't I
haven't done this before in a long time
so I have to force myself to do this
okay all right Buri treasure buried a a.
five met he takes turn digging B digs on
the second
day uh little K after each day they
switch B digs exactly X meters each
solid K digs y meters they become
curious who will dig up the treasure
first May who say the total dug depth
will exceed
8.5
okay no little B digs it up first
otherwise I'll put
yes so little
B B digs on the second day K digs so do
I print
out no if B digs it up first otherwise
print out yes
okay okay
okay what is
a 4.5
oh the total Doug dep will exceed 8.5 so
8.5 so it's 1 + 2 +
one plus 2 + one continue until greater
than
8.5 so
4.5 so that's 1 plus 2 + 1
can I just prove Force
this x y
K
okay x y
a
y
a okay now what I
do what's 8.5 so 8.45
who's turn is it be's turn
that's what
work no yes
yes okay so if it was not be
I have no idea if this will t or
not oh
T oh
um x + y + x + y + x + y + x + y + x + y
so is it a +0.5
/ uh mod by x +
y and
then is that what it is so we have 4.5
divided by
3 1.5 so then it would round up to two
so we do 1 + 2 + 1 plus two so that
gives
you six
let's try
that we're going to
do total is going to equal
to mod by X+ y
and then we take okay so this is going
to
be each each is total is going to equal
to each * x +
y that that'll be the total number while
it's less than a
no that shouldn't be right
[Music]
should be able to get the first problem
right at
least
uh uh
total what is total right now total six
so it's X's
term so we should to say
yes okay you know what let's do this
yes no 221 why is 221 yes 22
2 + 2 is 4
four
four should be the
minimum should be the
minimum yeah this should be the minimum
of for
run did not print it
didn't print it
do
[Music]
do
how do we do this this is modular
arithmetic I do XY XY XY until so on and
so
forth a
+0.5 mod
by
1 is four
um if we do like binary search no that's
not going to work I think this is this
makes the most sense but I just don't
know how to do this in case of it's
overshot because if it's overshot
CU I could take
three okay we overshot it and then we
we'll de increase
it so if this is not in it right so we
did one two one two one two one two
right so here we we overshot
it right now
now see if we could decrease y and then
decrease X so we get it
exactly underneath it so
if while total is greater than a plus
0.5
we we want to overshot it but we don't
want
to cause more
problems yeah
me yes yes no that's not what I want
oh
painful Let's Get r of
this so if it's greater than a +
5 see if we shot it we're going to
subtract the Y
first so we're first going to minus y
then we minus
X and we set it different so this we're
going to minus
y and then we minus
X and
then I think
no it's still not working two one
four not work
why is 24 yes
what wait each
is four okay
4.5 right I modded
by oh wait okay four four ided
three is
one one *
three is three is greater than 4 no it's
not it's not even greater than
4.5 uh I need that if statement back
again we need a if total than a plus
0.5 then we do
this
[Music]
else threats
what let's do this
this
[Music]
here be
f. those there troan when I'm running my
code doesn't make any
sense for
that
a mod X+ y
221 is yes
why 322 one
oh no you should subtract y
first so okay so this is okay
subtract y first and then we subtract
yal not y
uh in the end if we're subtracting so we
first sub y then subtract X subtract y
then
X
um if it was not y then that means
that it ended on X so then we should say
no
yeah so if not why say
no otherwise say
yes yeah
two two one
so what did we subtract we subtract Y
and then we subtract X but
then so we had 22
one originally it was what one mod by
four which is one so we had 2 +
2 which gives us
four e
oh no but we want the smallest one that
is the largest value that is just
smaller than
four smaller than
1.5 so it should have been one
so we what we wanted to do is start from
so one ID four one mod by four is one we
started here four is smaller
than one
now we just do the same thing
here right on the
end 2 two
one for
what tle on time
too add X add y x y
until we get up to
8.5
oh
um we could binary search
Maybe e
we do 8.5
minus I'm trying to think what can we
do this problem's
hard I'm not going to lie I'm probably
going to lose
rating I might just go to problem B
x +
y + x + y that dot has to be smaller
than 4.8 +
0.5 so in the case where we have 1
x one
y oh so there's two scenarios
we have one more X more than the y or
the Y's and X's are the same wait what
wait so I have ADD X add
y x then y x + y +
x then x + y + X+
y y + x + y + x so have 3x 2
y 3x or 2x 2
y or X there's no there's no basic
y so it's
always 3x 2 y
or 2x 2
y 2x + 1
y 2x + y
x + y and then there's X so X X Plus y
2x + y 3x + 2
y
uh 3x + 3 yit 3x +
y yeah 3x+ 3
y 4x + 3
y 4x + 4 y
so it's either 1 x is greater than
the the Y value
so if I take four if I take one mod by x
uh x + y so 1 by 4 would be one and I
say that this is X Plus y so I do four 2
four four and then I go down one so then
i' say two
2x + y x + y
x so if I do so 1 mod by
4 one so if I
do I'm getting really
I might I might go to bed right now I'm
so
tired why did I start this
contest all right I'm going to bed I'm a
losing rating today but at least I
attempted this
problem we'll go on a grind we will go
on a grind tomorrow we will yeah hope
you like this video video follow more
peace bye