#C1066. Remove Nodes Greater Than K

    ID: 39889 Type: Default 1000ms 256MiB

Remove Nodes Greater Than K

Remove Nodes Greater Than K

You are given a singly-linked list and an integer \( k \). Your task is to remove all the nodes in the linked list that have a value greater than \( k \). The removal should preserve the original order of the remaining nodes.

Task: Write a program that reads an integer \( k \), the number of nodes, followed by the node values of the linked list. Remove all nodes with values greater than \( k \) and output the resulting linked list. If the modified linked list is empty, output an empty line.

Note: You must process the input from stdin and output the result to stdout.

inputFormat

The input consists of three lines:

  • The first line contains a single integer \( k \), the threshold value.
  • The second line contains an integer \( n \), the number of nodes in the linked list.
  • The third line contains \( n \) space-separated integers representing the values of the linked list.

outputFormat

Output the values of the modified linked list in a single line, separated by a single space. If the list becomes empty after removals, output an empty line.

## sample
4
5
3 5 2 1 6
3 2 1