F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Binary Search Tree

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 122    Accepted Submission(s): 0


Problem Description
Suppose weĄŻve got a special BST ( Binary Search Tree ), according to the definition, all the nodes in this BST has a bigger value than its left child and, at the same time, smaller than its right child.
On the other hand, every node in this special BST has a weight. For every node, its weight is smaller than either of its child.
If every value is different and so is the weight, we can get an interesting conclusion, when all weights and values of the nodes are determined, the BST is determined as well. Because such a tree can be seen as a BST inserted in the order of weight and sorted by value.
Another common sense, the depth of a node is defined by one plus its distance to the root. So the rootĄŻs depth is one.
Well, it seems that this special BST is not special enough, obviously. I mean itĄŻs just a normal BST plus heapĄŻs characteristics. So I made it a little bit more difficult, only a little bit, trust me.
When dealing with a real-life problem, the access frequency of each node differs, and IĄŻll set it on the node. We call the access cost of a node as its access frequency multiplies the depth of it, and the access cost of an entire special BST as the sum of all access cost of its nodes.
Now, IĄŻll give you a data set contains all nodesĄŻ value, weight and access frequency, and you can modify the weight of some nodes, but every modify operation needs K extra cost. You can modify the weight to any real number, however, after that, every weight must still be different from each other. Your task is pretty simple, tell what the minimum sum of the access cost of this special BST and the extra cost is after the modify operations.
 

Input
The first line contains two positive integers N and K. N is the number of the nodes, and k is the extra cost needed for every modify operation. ( N<=70, 1<=K<=30000000 )
Next three lines, each line has N non-negative integers, indicate the value, weight and access frequency of each node separately. And all this integers are below or equal to 400000.
 

Output
One number, the minimum sum according to the description.
 

Sample Input
4 10 1 2 3 4 1 2 3 4 1 2 3 4
 

Sample Output
29
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 07:20:24, Gzip enabled