Problem list
Log in
#coci00431 · COCI 2016/2017 Contest 5

Tuna

Bronze II 1.0 s 64 MB

1 $s / 64$ $MB / 50$ points

Fisherman Šime caught ​$N$ ​ tunas last night. With the help of a special app, he offerred them for sale to a famous Japanese company that specializes in purchasing quality fish. In what way does the app estimate the value, or the price, of a tuna? Based on the photo of the tuna, the app returns two estimated values, ​$P$ ​ 1 ​ and ​$P$ ​ 2 ​ . If the difference between the estimates is less than or equal to ​$X$ ​ , then the higher value is taken. If the difference is strictly larger than ​$X$ ​ , the app returns a third estimate ​$P$ ​ 3 ​ and then that estimate is taken as the final value of the tuna. Write a programme that will, based on the given estimates (sometimes two, sometimes three of them) for each of ​$N$ ​ tunas, output the total value of caught tunas.

Input

The first line of input contains the integer ​$N$ ​ (1 ≤ ​$N$ ​ ≤ 20), the number of tunas from the task. The second line of input contains the integer ​$X$ ​ (1 ≤ ​$X$ ​ ≤ 10), the number from the task. Then, ​$N$ ​ blocks follow in one of the two following forms: ● In one line, two integers ​$P$ ​ 1 ​ and ​$P$ ​ 2 ​ (1 ≤ ​$P$ ​ 1 ​ , ​$P$ ​ 2 ​ ≤ 100) from the task, or ● In one line, two integers ​$P$ ​ _{1} ^{and}^{​}^{P} ​ _{2} ^{(1 ≤}^{​}^{P} ​ 1 ​ , ​$P$ ​ 2 ^{≤100) from the task, and in the second}

line integer ​$P$ ​ 3 ​ (1 ≤ ​$P$ ​ 3 ​ ≤ 100) from the task.

Output

The first and only line of output must contain the total value of caught tunas.

Example 1

Input
5
2
3 4
2 1
5 3
4 4
4 2

4
2
3 5
2 8
4
6 5
6 3
7

3
10
20 50
30
20 40
50
70 20
10
Output
output
output
19
22
90

Clarification of the second test case:

1 s / 64 MB / 50 points

Šime caught 4 tunas. For the first tuna, the app returned two estimates (3 and 5). Since the difference between these two estimates is less than or equal to 2, the value of the first tuna is ​5​. For the second tuna, the difference between the first two estimates (2 and 8) is higher than 2, so the app returned a third estimate, ​4​. The third tuna’s value is ​6​ (6 – 5 ≤ 2), and the value of the fourth tuna is taken as the third estimate, ​7​, because the difference between the given estimates (6 and 3) is higher than 2.

Task Pareto 1 s / 64 MB / 80 points

Paret’s principle, also known as the “80/20 rule”, states that in many situations 80% of results come from 20% of (the most important) causes. For instance, Microsoft found that, by fixing 20% of most commonly reported bugs, they would eliminate 80% of downtime in their systems. In the business world, it is often said that 80% of income comes from 20% of the most important clients. In the world of mobile games, when it comes to games with free basic functionality, 50% of profit comes from 0.5% of players. Some say that 80% of your success will come from 20% of your activities.

It is a known fact that 80% of the world’s goods is owned by 20% of (the richest) people. Your task is to check the validity of this rule based on the bank accounts owned by clients of a single bank. Is it true that 20% of accounts hold 80% of the total money? Does a stronger claim hold, for instance, that only 10% of accounts hold 85% of the total money?

More precisely: based on the given account balances of ​N bank clients, your task is to find

numbers ​A ​ and ​B with the maximal difference ​B - A such that we can say that

precisely ​A ​ % of accounts hold ​B ​ % of the total money​ of all clients of the bank.

Example 2

Input
The first line of input contains the integer ​N
​
 (1 ≤ ​N
​
≤ 300 000), the number of clients in the
bank.
The following line contains ​N
​
 integers from the interval [0, 100 000 000], the balances of
bank accounts in euros.
Output
In two lines, you must output two real numbers from the task, ​A
​
 and ​B
​
, omitting the
percentage sign. Solution with the greatest B - A difference will be ​unique​. A deviation from
the official solution for less than 0.01 will be tolerated.

SAMPLE TEST

Example 3

Input
2
100 200

8
100100 10 100 1000 1 10100
90100 100100
Output
output
50.0
66.66666666666666

37.5
96.28172769816027





Task Pareto
1 s / 64 MB / 80 points

Clarification of the first test case:​ 50% of accounts (one account, the one with 200 euros), contains two thirds, 66.666667% of the total money.

Source
COCI 2016/2017 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code