Codeforces Div. 2 problem 4B

I am doing the ladder for Div. 2 B on codeforces, and just did the 31st question.
http://codeforces.com/problemset/problem/4/B

I have been trying this simplw problem since morning but couldn’t wrap my head around it. Just couldn’t. Then I finally looked at the tutorial and used it to understand how to solve the problem. I feel bad that I saw the problem, I can’t keep doing this.
I have done this for a few more problem in the past, and i feel bad when i see how easy the solution is. If only I had though harder.
I need to do full justice to every problem I’m solving.
Dunno why i’m not able to solve problems today. They are not really any hard. I should be able to solve them. There;s so much to do! How will i ever be able to just pass easy problems in one single go? It shouldn’t take more than 20 mins max to solve these problems.
I just want to write here how i solved this particular problem eventually. I could just copy paste the tutorial here, but then i wouldn;t be able to learn anything!

Algorithm:-
1. Take the sum of all the lower bounds (minTime) as sm1 and the upper bounds (maxTime) as sm2, and check if sumTime lies in the range sm1<=sumTime<=sm2.
2. If not, then just print NO and return, else print YES and move ahead.
3. Declare a vector to keep the schedule<int> of each day for Peter’s study hours. Initialise it with the lower bound (minTime) for every day. Take another vector upper<int>, to save the upper bounds (maxTime) for every day.
4. So basically these many hours have been done by Peter already from the whole quota of sumTime. Hence, need to sumTime – sm1, these many hours still need to be given the the subject.
4.1. Start looping ove the array schedule for its whole length.
5. Calculate delta = min(need, upper[i] – schedule[i]).
6. Update schedule[i] +=delta; and need -=delta;
7. You can break when need=0, but that’s not totally necessary.

So basically, what we are doing is, we assigned to the schedule of each day, the minTime set by Peter’s parents for that day. Then we see how many hours of study are left in total. Now for the schedule of every day, we give it the minimum of either the full need which is left and the total no of hours for that day (maxTime – minTime).

I’m spending so much time to write this stupid blog post, because i feel bad of having looked at the algorithm and then coding it.

A contest is about to begin on codeforces in about 2 hours. I hope i do well and am able to do atleast 2 questions.

-jigsaw.

Placement season musings #1

It’s been almost a month since I have visited this blog, let alone think of writing something. I have been extremely busy with ongoing placements (rejections mostly). The last one and a half months have been hard for me, probably the hardest time I have ever experienced in life. But I did bring this upon myself, with neglecting programming since so many years which I could’ve made good use of. I coudn’t really code in the month of June, because of Dad’s health, constant stream of guests, internship and so many more things that were piled up on me. Nevertheless, each of those things did teach me a lot of virtues, and shaped me into a much more mature person than I was. The hardest things in life make us into what we become. We are nothing but our struggle.
I’m going to be brief in this post, and there are no characters I can spare for regrets.
I have gone through a lot lately, understood different things about myself, my caliber, my motivations, my ability, my strengths, my weaknesses, my inner self, my virtures, my apprehensions and a whole lot of things. Now that I am regularly solving programming puzzles and questions, I feel that it is not as if programming isnt my cup of tea like I used to think. Like I had always been afraid of. Even in just a month, I feel like I am already a decent programmer, but there is still a long long LONG way to go!
I don’t know how things will turn out for me in the end, but one thing college life has taught me is that when I work hard, I have always reaped the results. Granted, I am really late in realising the fact that I lack greatly as a programmer, but now I am trying to work hard. I am able to solve most of the linked list, arrays and trees questions with my logic and not too much struggle. The real problem I face in the questions of Dynamic Programming and graph applications.
The cold fact I need to understand (and probably have) is that programming needs practice. A LOT of practice. And there is not alternative to hard work.

I hadn;t worked hard up till now, but now i want to fully utilise my final year to not just bag a great offer, but also to become an able coder. Because one thing I know for sure is that once college ends, I won’t be able to learn programming significantly. Like it or not, I will be caught up in the rat race of industry life for a few years at least. Therefore, I want to fully utilise that time becoming an able programmer. Because for a good programmer, there will always be jobs in the market. There will always be opportunities for people who are technically astute.

I don;t want to form a passive approach towards problem solving for myself. I want to learn, and grow as a programmer in this final year of my life. Now, I have always been a kind of a person who stays motivated in a group of friends. In college, i haven’t really been able to form a group of people with whom I can practice programming together. There are a few people, but I also need to match their level to be able to sit with them and code, or they have to be accomodating enough. This is one of the biggest factors I feel that deterred me from learning programming all this time. The road will be tough when I am alone on it, but I will put in my best nevertheless. Maybe I could make this blog my companion.
Secondly, I want to inculcate discipline in my life, and not just bank on motivation. Motivation is a bursty and momentary thing. It comes and goes. But discipline is a permanent phenomenon. One sowed, it keeps on reaping fruit without the need to motivation every now and then.

Whenever you are trying to learn something, or exploring a field beyond just what lies on the top, there is always a hard phase. It’s this phase of my going on. No matter how hard you strike at the thing, you are not able to break through. There is a lot of frustration, tantrum throwing, constant thoughtsof giving up, ubiquitous laziness and so many more things that stand in the path of you and your goal of becoming good at something. I pray that I am able to withstand this phase with most of the insanity left in me (:p), and I can cross over to the other side, the side where I can really call myself a good programmer. Wouldn’t it be amazing to work hard for that one day? I hope i am able to stick to this resolve of not giving up on engineering, of not giving up on programming, and of not giving  up on me.

My tryst with programming is getting more and more interesting.