CSES - Smallest elements

The list has nn integers. Implement a test, where the sum of the n/10n/10 smallest elements of the list is computed.

Implement the test in three different ways:

  1. Sort the list and compute the sum of the first n/10n/10 elements.
  2. Create an empty heap and move the elements of the list into the heap one at a time using the function heapq.heappush. Then extract n/10n/10 elements from the heap and add them up.
  3. Turn the list into a heap in linear time using the function heapq.heapify. Then extract n/10n/10 elements from the heap and add them up.

Perform the test using n=107n=10^7 with each element chosen randomly from the range 11091 \dots 10^9. Check that each implementation returns the same answer.

In this task, you get a point automatically, when you report your results and the code you used, and push the submit button.

Time for Algorithm 1: s

Time for Algorithm 2: s

Time for Algorithm 3: s

The code you used: