ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Структуры данных > задача:


50771 - BST Level Sum

Гость
• Вопросы к жюри (1)

Задачи раздела

• 50803 - Sum of the depths in BST
• 50805 - Sum of the weights in a BST
• 50818 - Depth Limited BST
• 50770 - Average Depth
• 50836 - Censored
• 50816 - Largest Sum Path
• 50772 - The Path of a Node
• 50863 - Total Access Cost of a BST
• 50771 - BST Level Sum
• 50773 - Balanced Sum Tree
• 50411 - Sum of the Leaves
• 50722 - Problemi i shkencetarit

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

BST Level Sum

Question: Mr. Uka is having a research. On his research, he is using Binary Search Trees. And, he has to calculate the sum of the nodes in the given level.

For some reason, the tree can grow very deep, and, this causes problems. Thus, he wants to limit the depth to a certain value. The nodes which go deeper than the given limit will be ignored.

Write a program that is going to read the given list of values, and insert them into the BST. And calculate the sum of the nodes in the given level.

Input specification: In the first line, you will be given three integers:

  • max depth: an integer between 0 and 15
  • Sum level: the level to calculate the sum of the numbers, an integer between 0 and 15
  • n: the number of the elements in the following line to insert into BST; an integer between 0 and 50000

Output specification
Show sum of the numbers in the given level.
Note: If there exists a number in BST, the number will be ignored.

 Sample Input I     Sample Output I   
 2 1 10
 6 2 4 8 5 2 3 7 4 1
 10

Sum of the elements in level 1 is (8+2) 10
Для отправки решений необходимо выполнить вход.

www.contester.ru