Lower Bound

Time limit: 20ms
Memory limit: 256mb

-------------------------Copy the following code, complete it and submit---------------------

/*
I, <Your Full Name>, am submitting the assignment for
an individual project.
I declare that the assignment here submitted is original except for
source material explicitly acknowledged, the piece of work, or a part
of the piece of work has not been submitted for more than one purpose
(i.e. to satisfy the requirements in two different courses) without
declaration. I also acknowledge that I am aware of University policy
and regulations on honesty in academic work, and of the disciplinary
guidelines and procedures applicable to breaches of such policy and
regulations, as contained in the University website
http://www.cuhk.edu.hk/policy/academichonesty/.
It is also understood that assignments without a properly signed
declaration by the student concerned will not be graded by the
teacher(s).
*/


#include <stdio.h>
#include <stdlib.h>

#define INF -999999

struct treeNode {
    int value;
    struct treeNode* left;
    struct treeNode* right;
};

typedef struct treeNode* TreeNode;

TreeNode CreateTreeNode(int value) {
    TreeNode node = (TreeNode) malloc(sizeof(struct treeNode));
    node->value = value;
    node->left = NULL;
    node->right = NULL;

    return node;
}

TreeNode Insert(TreeNode root, int value) {
    // write your code here

}

// If there is no element in BST, which is no less than the value, return INF
// This function should cost O(log N) time
int LowerBound(TreeNode root, int value) {
    // write your code here
    
}


int main() {
    int n, operation, value;
    scanf("%d", &n);

    TreeNode root = NULL;

    for (int i=0;i<n;i++) {
        scanf("%d", &value);
        root = Insert(root, value);
    }

    scanf("%d", &n);

    for (int i=0;i<n;i++) {
        scanf("%d", &value);
        printf("%d\n", LowerBound(root, value));
    }
}

-----------------------------------------End of Code-----------------------------------------
Description:
Calculate the lower bound of a number in the binary search tree. The lower bound of a number A is the first number in the binary search tree which is not less than A.
It must cost O(log N) time to calculate the lower bound of a number.

Input:
The first line contains one integer: N;
The second line contains N integers, which are used to build the binary search tree;
The third line contains one integer: N;
The fourth line contains N integers;

Output:
For each integer in the fourth line, output its lower bound in the binary search tree. 

Sample Input 1:
9
4 2 1 3 7 6 5 9 10
4
4 8 11 0

Sample Output 1:
4
9
-999999
1

Submit