#K47542. Sum of Values in a Binary Tree Greater Than or Equal to K

    ID: 28221 Type: Default 1000ms 256MiB

Sum of Values in a Binary Tree Greater Than or Equal to K

Sum of Values in a Binary Tree Greater Than or Equal to K

You are given a binary tree provided in level-order traversal format. The tree nodes are represented by integers, and missing nodes are denoted by null. Given an integer k, your task is to calculate the sum of all node values in the tree that are greater than or equal to k.

For example, consider the binary tree represented by the level-order list 5 3 8 1 4 7 9 and k = 5. The sum of all nodes with values ≥ 5 is 29. You need to implement a solution that reads input from the standard input and outputs the result to the standard output.

Note: When reading the tree nodes, the token null (case-sensitive) indicates a missing (null) node.

inputFormat

The input is given via standard input and consists of two lines:

  1. The first line contains an integer k.
  2. The second line contains space-separated tokens representing the tree nodes in level-order traversal. Use the token null to denote missing nodes.

outputFormat

Output a single integer representing the sum of all node values in the binary tree that are greater than or equal to k.

## sample
5
5 3 8 1 4 7 9
29