This video demonstrates systematic approaches to solving competitive programming problems, including mathematical formulas for minimum operations (Problem A: (max-min+1)/2), greedy strategies for array optimization (Problem B: sum(B) + max(A)), parity-based flipping techniques (Problem C1), strategic element selection (Problem C2), binary search on answers (Problem D), and tree DP with subtree maximums (Problem E). The key insight is that complex problems often reduce to simpler patterns when analyzed systematically, with solutions requiring careful observation of problem constraints and optimal operation sequences.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Codeforces Round 1100 (Div. 1 + Div. 2) | Solutions by ArpaAdded:
Hey folks.
I'm going to up solve Codeforces round 1100 today for you.
Up solving all problems from A to E. I was unable to solve problem F actually.
Um I think I was very close. My time complexity was not good enough.
Let's see uh how I performed in this contest. I solved problem A 2 minutes, B in 5 minutes, C1 in 3 minutes, C2 in 20 minutes.
Just so you know that those are wrong answer on test one, which are yeah, not important at all.
Then I solved C2 uh in 20 minutes. Those are wrong answer on test one, by the way.
Then I solved uh problem D in almost 30 minutes, problem E in uh 50 minutes.
And I was unable to solve problem F in 1 hour and 10 minutes, unfortunately. I tried.
I think I was close, but yeah.
Finally not able to do that. Great. Uh let's go over the problems one by one.
Let's just start from problem A. Problem A says that uh at each operation you can get numbers closer to X by one.
And what is the minimum number of uh operations?
The clear thing here is the difference between minimum and maximum uh differs change by two every time unless it's the last operation, which maybe changed by one.
Uh so, we find the difference and we divide it by two and take seal to make sure uh we are handling that case correctly.
So, max element minus min element plus one divided by two and you can see on examples like 5 minus 1 4 divided by 2 it's 2.
Or let's say here 7 minus 1 it's 6 divided by 2 it's 3.
Or here 5 minus 2 it's 3 3 divided by 2 but taking seal uh it's 2 so on. Great. Let's move on.
Let's move to the problem B.
Uh in problem B uh what we should do is uh first we're starting with trying to maximize B for sure because um B is more important. B we are doing sum over it.
So, first let's try to make B as large as possible. So, if AI is larger than BI, let's swap them to make BI greater. Okay.
Then we may swap one A with a B with its corresponding B to make the answer even larger. Okay?
Uh in that case the answer will be the previous sum minus BI then plus BI then plus AI. How?
Uh let me wait for this to load and I'll show you.
Uh still waiting for this to load.
Okay.
Mhm still waiting. Okay, finally.
Okay, so So this is my array A.
This is array B.
Then when I swap these two, the answer will be sum of B sum of B minus uh minus BI to remove this from here.
Then plus AI because this AI will be added to this sum.
And finally, plus BI because this new BI we are considering that it will be the maximum.
Okay? It may be not, but um this is not a problem for us.
This will not exceed the answer. This is one of the candidates for the answer.
Okay?
So we calculate the maximum over all this and that is the answer. So look at this. I get all A's then I all B's and if B is a large B is less BI is less than AI, I swap AI and BI. Then you can see a fact here. So this BI will um go outside this that BI and this is sum plus AI. So what is a best thing here?
To have the maximum AI. So the answer is sum of B plus the maximum of A and that's it. So, you can see maximum of A plus sum of B.
That's it.
Okay, then let's go into the next problem which is C1.
In this problem, what we need to do is just making all numbers negative and it's always possible. We come from right to left. We see each positive element, we flip it. Uh we then we continue to the left and every time we see a positive element, we flip it. Okay?
The only thing that uh we need to take care about is um when we are going to left, we already had flipped this prefix many times. So, we need just to keep the parity of how many times I already uh inverted numbers.
Uh and using that, I can calculate >> [clears throat] >> what should I do.
Okay.
Let's see. So, first of all, I start with reading um array A.
Then first inverse the I didn't invert anything to to my right.
Then I have my answer.
Then there are two conditions. A I is more than zero and it's or by inverted.
Why? Because for example, if I inverted uh in the right and this number is negative, it means that this number is now positive. So, I need to invert it again.
Uh given that, I need to push this as I need to have this uh I in my answers. Then I will flip the inversion and go to the left, finally print the answer. This is a bit tricky to understand. Make sure you understand this before we continue to problem C2 because it's needed in C2.
Okay.
In problem C2, uh it was not very easy for me.
Um I don't know what what I I I implemented a DP solution from scratch and it was wrong and then I started all over again. It was pain. Uh okay. Uh but but the solution is not that hard. We can handle it.
Uh let's start like this.
We for sure we are for sure going to do some operations. If you are not doing some operations, that's it, okay?
But consider that we are doing some operations.
And we have Let's let's fix the rightmost element that I do operation on that. I do an operation on that, okay?
So, let's consider the leftmost element that I do operation that. For example, here uh the leftmost the leftmost is two, okay? I'm going to do operations on one and two and the left Sorry, the rightmost is uh two. Or for example, here the rightmost is seven. Where is that? 1 2 3 4 5 6 7. This is a the rightmost I'm going to do some operation over that, okay?
So, let's consider that element.
When I went to do that flip.
I can make sure that before I do that, like here, so if if you read this example carefully, you could solve the problem. Like this is a revealing the solution.
So, before I do this operation, I make sure that all numbers from its left are negative.
Then, I'll invert all these numbers and those numbers will be positive and only this number will be negative.
Okay?
And uh yeah, this is this is pretty tricky, okay? So, how I can make all these numbers negative? Using C1, okay? And then I will invert this, too. So, just just we need a little bit of calculations.
Sorry.
Okay, I just start with reading the input. Then, I'll have some sum and some absolute which I'll calculate when I'm going from left to right.
And I will have some answer. And I will have IND which shows that which index I want to pick.
Then, [snorts] uh I iterate over I from left to right.
And finally, I decrease the number from my sum and [snorts] I go over go over. So, if I this number is positive, so I can do operation on that. And this answer, which is sum abs, which comes from my left, minus AI, which is making this number negative, plus sum, which are sum of numbers to the right, This is bigger than ans, so I need to update the answer.
So, I set the answer. I set the index.
And I update the sum apps.
Which is to the left. Finally, I define my vector. If index is not negative one, I start by Yeah, I do C1 actually and print the answer. That's it.
Let's move on. Let's move on to the problem D.
Yeah.
>> [snorts] >> I I think there exists a an easier solution to this problem, but yeah. So, I do binary search over the answer.
And now the array A and B are zeros and ones, right?
>> [snorts] >> Uh let me show you how they are zeros and ones, okay?
For example, let me come with some uh Let me come with this.
>> [snorts] >> Okay.
Okay.
Um consider the ans answer is eight, right?
So, this is zero zero one zero one one.
So, I put one when this is greater than eight, and I put zero when the number is less than eight, okay? Zero zero zero zero one one, okay?
Uh >> [sighs and yawns] >> So, I can do some operations, right?
>> [snorts] >> And I pick something the then I then this will be sorted and the smaller one goes to upper um greater one goes to lower. So, if I remove this, the new will be zero and one, okay?
So, first of all, what I can do is removing these numbers.
Like I can easily drop this because I can like pick them together and delete those two zeros.
>> [snorts] >> Then also, I can remove this.
Right?
I pick these together and remove that.
Then, I can remove this.
And now, I can pick these two together and have zero one. And now I have this.
Finally, I can convert this to one one.
So, this is the answer.
Okay. So, what I mean?
What I mean is first of all, if at any moment of removing these columns or whatever you are calling it, at every moment, if number of ones is more than number of zeros, that's it. The answer is true.
>> [snorts] >> Otherwise, let's try to remove some zeros as much as possible.
Okay. So, consider some sub array.
Sorry.
Consider some sub array that you can find a lot of zeros in it like this.
I [snorts] can remove all of them and replace them with two zeros.
So, what I will do is exactly doing this.
Trying to remove uh large segments that have a lot of zeros and converting them to to something like this.
>> [snorts] >> And finally, uh trying to see if the number of ones is more than number of zeros.
So, what I understand from my solution, so I implemented this and got AC, but now I'm trying to improve my solution.
I think that we have some uh We have some columns with two ones.
And other columns.
Let's convert.
No.
>> [snorts] >> Okay. So, I'll I'm going to describe the solution I implemented. Let's see.
So, first of all, I read see the input, then I do my binary search. Then I have my CNT.
And I have some something named escape.
That means that we are trying to escape the current salary or not, okay?
So, if escape is true, uh and both numbers or at least one of them is less than mid, I'll keep this keeping I'll keep this and just continue from this index.
Otherwise, I'll add those two numbers.
And then the skip will be if both numbers are less than meet. So, both are zero.
And finally, I'll check if number of ones is more than number of zeros. I I'm pretty sure you can find easier solution.
There is something to make it easier.
I'm not sure I I'm sure, but I don't know how to implement that.
How to find that, but there is something. There is something to uh Yeah. Make it easier to understand, easier to implement a a bit. Yeah.
And the the conditions can be simplified, I mean. Okay, great. Let's dive into the last problem, problem E.
Oh.
Oh, this was not easy.
This was not easy for me.
Uh Oh, and the problem F was unsolvable, right? Okay.
>> [snorts] >> Uh problem E.
The first thing to observe in this problem is every time we are picking a leaf, we are picking a larger leaf.
Okay.
So, when one by one, one by one, when we are uh going, when we are finding the next leaf, we are picking a better one. We are picking a larger one, okay?
So, let's define a DP.
And yeah, another note.
The node N will be the last node that it remain, okay?
So, let's root the tree from node A.
Then, uh then let's say DP of V to be the number of ways the number of different sets I can have when for the first time I insert V to the set.
Okay? So, the number of different ways of set S when V is being inserted to S itself.
This is This is the definition for uh This is the definition for S.
This is the definition for DP.
So, let's try to calculate DP, okay?
So, to calculate DPV, you can see So, this is root of my tree.
These are vertices. This is V. This has a subtree.
So, consider the last element before V in S. So, S is something like this, then U, and then V. I want to iterate over U.
Okay?
U is for sure less than V.
For sure, there should be no vertex here larger than U.
>> [snorts] >> It means that let's calculate MX of V to be maximum index of a vertex in subtree of V is strict sub subtree not V not including V itself.
So, U should be strictly more than max of V.
It means that U can So, so, so, DP V is sum of >> [snorts] >> max mxv plus one to DPV DPU.
Okay.
This is the sum.
This is DPV.
This way you can calculate DP but this is of n squared.
We can fix that using partial sum over DP. We can fix that.
But there is a still a problem here.
Problem is this doesn't work for root itself.
For root we need to do something else.
So, root has some root has some subtree that the second maximum is here.
The only DPs that can contribute to root's DP are here. Who are they?
Consider the maximum here.
The maximum vertex here.
Let's name it X or let's name it T.
All vertices here that are larger than T can contribute to the answer.
The answer is sum of DPs in this subtree that are larger than T.
Yeah.
Let me show you the code.
So, I started with implementing my mint struct.
Then >> [sighs] >> and then I receive the input. I do DFS to find the MX for every vertex.
Now, I'll have my max leaf.
The max leaf will be the leaf which is maximum. The The first leaf that we asserted is that.
Then I have my partial sum, then DP total, which is total DP so far.
Sum of all DPs so far. DP sum, maximum leaf, and DP of maximum leaf. This is one. Others are zero.
Then I start from max leaf plus one and I go to N minus two.
If MX of V is larger than V, yeah, for sure DP of V is zero. Otherwise DP will be DP DP total minus DP sum of max V.
Uh great.
So, this this is this is probably using partial sum.
Then I update DP sum and also DP total.
Then I change the definition for maximum to include the numbers themselves.
Then I sort all adjacents of a vertex n - 1 and move uh the I I need the first two, right? So, I sort them.
Uh then then mhm if maximum leaf is n - 1, that's it.
Otherwise, I go calculate answer. I go in this child.
This is my parent.
And this is how Oh, this is not needed.
This is not needed.
Because size will be If size is one, it's leaf already.
That's it. Okay. So uh the answer will So So, I want to find the vertices in subtree of these children which are which their index is better is larger than this.
The second minimum.
Then I go into calculate answer is v if v is more than t, dpv can contribute to the answer, otherwise zero.
Then I go over all vertices and calculate recursively. Thank you.
Thank you for watching, guys.
Um we have a few hours before this contest, so I hope for you good ratings.
Uh see you tomorrow morning in Lead Code up-solving session. Thank you. Uh Bye-bye.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











