Midyear Online Camp - Contest 03
Contest link: https://codeforces.com/contests/267777
A. Amr and Even Integers
Credits: Amr Salama
This was the easiest problem in the contest. You are asked to round the division result to be even.
Note:
ceil
will always rounds the result to the upper boundceil(2.3) = 3
.floor
will always rounds the result to the lower boundfloor(3.9) = 3
.round
will rounds the result towards the nearest integerround(2.6) = 3
,round(3.2) = 3
.
We don’t need to use any of them, We can simply calculate the integer division and check whether it is odd or not, if it is odd then add one to the result, otherwise print the result.
B. Omar and Bike
Credits: Ismail Akram
To solve this problem you need to note input constraint (m <= n
), So there is a possibility that m
could be equal to n
, and so Omar may not save any money at all in this case (n - m = 0
), and you should print -1
in this case.
Otherwise, the result is the ceil
of k / (n-m)
. If you didn’t check for -1
case first, you may have run time error
due to division by zero.
C. Ismail’s Exams
Credits: Ismail Akram
This problem is direct implementation. First, you need to note that Ismail needs at least n/2
to pass. So read the string, count how many 1
in it, and print the difference between n/2
and the count of 1
in the string, Note this may be negative, in this case print 0 (Ismail already passed without Amr’s help).
Another C++ solution