Here are the corrections:
- You are first supposed to take x(amount to be withdrawn) as input and then y(balance). But you are first taking y as input and then x.
- The extra 0.5 is also to be deducted from the balance, so this changes the condition in the inner if.
[x<=y changed to x+0.5<=y]
Here is the corrected solution: http://www.codechef.com/viewsolution/4377646
There is also no need for checking x>=0&&x<=2000 and also y>=0&&y<=2000, these values simply tell you the range of the input for the problem. There are known as constraints.
The use of constraints:
The most basic use of constraints is that they let you decide the type of data type to use. Suppose if 0<=x<=1012, then you had to declare x as long long instead of int.
In more complex problems they help you decide the algorithm to use to solve the problem based on the time limit. You calculate the time complexity and check from the constraints that it will execute in the time limit specified.
So, there is no need for these checks, the input will definitely be in this range only.
Here is the solution without these checks: