Problems
Farmer John has a binary tree with
He has been tasked by the Federal Bovine Intermediary (FBI) with finding an approximate median value within this tree, and has devised a clever algorithm to do so.
He starts at the last node
The FBI has also given Farmer John a list of
Input
The first line of input contains
The next
The next line contains
The next
Output
Output
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 20 | |
| #2 | 30 | |
| #3 | 50 | |
Example
5
10 10000
30 1000
20 100
50 10
40 1
11
55
50
45
40
35
30
25
20
15
10
5
111
101
101
100
100
100
100
0
11
11
111
To make the median approximation equal
To make the median approximation equal