Job Scheduling Medium

+100 PTS

Before you start the test, check out our tutorial challenge

  • TYPE CODE PRACTICE CHALLENGE
  • LANGUAGES BASH, C, C++, C# AND 21 MORE
    LANGUAGES BASH, C, C++, C#, CLOJURE, ELIXIR, ERLANG, GO, GROOVY, HASKELL, JAVA, JAVASCRIPT, JULIA, KOTLIN, NIM, PERL, PHP, PYTHON2, PYTHON, RUBY, RUST, SCALA, SWIFT, TYPESCRIPT, VB
  • TIME ~25MIN

Job Scheduling

Challenge outline

Hello and welcome to the challenge!


In this challenge you have to schedule your tasks. This time you'll use the Shortest Job First algorithm. In this way, you perform tasks from the shortest to the longest. Additionally, in your set of tasks is one "Special task" and your goal is to calculate how many hours you need to end this task. If the jobs take the same time then it is First In First Out (FIFO).

Input

  • The first line of the standard input contains the number of tasks you have (N).
  • The second line contains N integers t1, t2,..., tN (separated by a single space), denoting the number of hours you need to do each task.
  • The third line contains one integer denoting index (i) of the "Special Task" (zero-indexed).

Output

  • To the standard output print one integer denoting the number of hours you need to do "Special Task"

Constraints

  • 0 < N <= 25
  • 0 < t1, t2,..., tN <= 100
  • 0 <= i < N


You can solve this programming contest in C#, C++, Java, Ruby, JavaScript, Python, PHP and many more languages. If you want, you can also take part in other June 2019 competitions. Below you can find some of them:



Did you like this challenge and would like to try your hand at some interesting big programming competitions? Check what’s all over the news in tech world in June 2019 in our article with upcoming IT Conferences, Hackathons and Online Challenges in July 2019.


Have fun and good luck! :)