In this Optimization we will Cure all the infected person before moving to next country.
We will have two cases
1. when x < arr[i]
2. x >= arr[i]
Case 1: x < arr[i]
Here we will cure all the infected person thus we will not increment i until x >= arr[i]
Case 2: x >= arr[i]
Since we have vaccines greater than the infected person we can use the vaccines equal to arr[i].
Example
12 19 20
x = 4
x < arr[0]
arr[0] = 12 - 4 = 8
And x becomes
x = 8
arr[0] = 16
hence at day 2
arr[0] = 16 - 8 = 8
x = 16
x = arr[0]
hence at day 3
all patients can be cured.
By Chirayu Jain