Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Equal Division There are N teams in a software company. The ith team has Bi employees in it and a total budget of Ai units

Equal Division

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.

Constraints:

  • 1N10^5
  • 0Ai10^9
  • 1Bi10^9

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.

Output Format:

In a single line, print the minimum number of revisions needed so that for each team, equal distribution of their budget among the employees is possible.

SAMPLE INPUT

3 1 1 3 7 5 4 

SAMPLE OUTPUT

4 

Explanation

Initially, the budges of the teams are 1, 3 and 5.

In the first revision, the company will increase the budget for first 2 teams by 1. This will make the budgets as 2, 4 and 5.

In next 3 revisions, the company will increase the budget of first 3 teams by 1.

The final budgets will be 5, 7 and 8 which can now be equally distributed within each team.

You cannot achieve the equal distribution characteristic in less than four revisions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

6. What risks do you see in these packaging decisions?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago