There are N teams in a software company. The ith team has Bi employees in it and a total budget of Ai units of money. Each team has to divide their budget within their employees equally. But for some teams, it's not possible to divide the budget equally.
Therefore, the company have to perform revisions in the teams' budget sizes.
In one revision, to revise the budget of ith team, the budget of the first i teams has to be increased by 1 .
Your task is to find the minimum number of revisions needed so that for each team, equal distribution of their budget among the employees is possible.
Answers
Answered by
3
ਆ ਤਾਂ ਮੈਂਨੂੰ ਆਉਂਦਾ ਨੀ ਜੀ ਪਰ ਚੰਗਾ ਸਵਾਲ ਹੈ
ਆ
ਆ
Answered by
0
The final budgets will be 5, 7, and 8
- Input Format:- The first line contains an integer N, denoting the number of teams.
- Next N lines contain two space-separated integers, Ai and Bi, each.
- Constraints
1<=N<=105
0<=A<=109
1<=B<=109
- Output Format:- Print the fewest modifications necessary each line to enable each team to allocate its budget equally among its members.
- Input
3
1 1
3 7
5 4
- Output
4
- The teams' starting budgets are 1, 3, and 5.
- The business will increase the budget for the first two teams by one in the first revision.
- This will result in budgets of 2, 4, and 5.
- The business will increase the budgets of the first three teams by one in each of the following three revisions.
- The final budgets will be 5, 7, and 8, which can now be split equally among the teams.
- It takes at least four revisions to attain the equal distribution characteristic.
Hence, the final budgets will be 5, 7, and 8
#SPJ2
Similar questions