Tuna
의견: 0
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.
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.
The first and only line of output must contain the total value of caught tunas.
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
10output
output
19
22
90Clarification 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.
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.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 TEST2
100 200
8
100100 10 100 1000 1 10100
90100 100100output
50.0
66.66666666666666
37.5
96.28172769816027
Task Pareto
1 s / 64 MB / 80 pointsClarification of the first test case: 50% of accounts (one account, the one with 200 euros), contains
two thirds, 66.666667% of the total money.
평가 및 의견
Tuna
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Tuna