Telephone connections
Practice
3.2 (8 votes)
Real world
Algorithms
Dynamic programming
Introduction to dynamic programming 1
Problem
87% Success 2878 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are working on the city construction project. You have A houses in the city. You have to divide these houses into localities such that every locality has at least one house. Also, every house in a locality should have a telephone connection wire with each of the other houses in the locality.

You are given integers A and B.   

Task

Print the minimum and the maximum number of telephone connections possible if you design the city accordingly.

Example

Assumptions

  • A = 6
  • B = 3

Approach

A minimum number of telephone connections can be achieved if houses were split into localities consisting of 2 houses each. The maximum number can be achieved if localities were split into localities of 1, 1, and 4 houses.

Ans = 3 6

Function description

Complete the function Minmax() which takes an integer and an integer B. This function takes the following parameters and returns the required answer: 

  • A: Represents the number of houses
  • B: Represents the number of localities

Input format

Note: This is the input format you must use to provide custom input (available above the Compile and Test button).

  • The first line contains an integer A denoting the number of houses.
  • The second line contains an integer B denoting the number of localities.

Output format

Print the minimum and the maximum number of telephone connections possible if you design the city accordingly.

Constraints

\(1\leq B\leq A\leq 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
65 votes
Tags:
Ad-HocAlgorithmsApprovedEasyOpen
Points:20
126 votes
Tags:
AlgorithmsDynamic ProgrammingEasy
Points:20
29 votes
Tags:
Ad-HocApprovedEasyImplementationOpen