April Fools
InterviewTime limit1sMemory limit1024 MB
Each newspaper prints exactly one false fact. Find the smallest and largest total number of false facts that can be consistent with this.
- Level
Medium4 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
On April Fools Day newspapers like to fool their readers by publishing false and usually absurd facts. For example, a fact stating that today Vilnius television tower was brought down by wind.
You are given a range of facts which were published by each of the different newspapers. These facts are denoted by natural numbers from to . For example:
- Newspaper 1: 1, 2, 5
- Newspaper 2: 2, 3, 4
- Newspaper 3: 1, 6
You also know that this April Fools Day each of the newspapers published exactly one false fact.
Find the smallest and the biggest number of false facts that could have been published today.
Input
The first line contains two integers and , separated by a space.
The facts published by each newspaper are described on the remaining lines. On line , the number is given, the count of facts published by the -th newspaper (). On line , the integers are given, separated by spaces, with and . Every fact from to is published by at least one newspaper.
Output
Print two numbers separated by a space: the smallest and the biggest number of false facts that could have been published that day.