Server Queue Challenge

Company: Rubrik_8nov

Difficulty: hard

Problem Statement

Server Queue Challenge Alice administers a server farm. The execution queue holds n pending tasks, task1, task2, ..., taskn , listed from highest priority (front) to lowest priority (back). Task i has a complexity rating a_i . Alice's own urgent job sits at the very back of the queue, behind all n tasks, and she wants to move it to the very front. Alice may repeat the following two operations, in any order, as many times as she likes. Priority boost — if a task is standing immediately ahead of Alice's job, she may move her job ahead of that task by paying processing credits equal to that task's complexity. Her job advances exactly one place, and the task she just overtook is now immediately behind her job. Task reordering — using administrative privileges she may exchange the tasks that currently occupy queue positions i and j ( 1 <= i < j <= n ) at a cost of j - i credits. Positions are counted over the n tasks only; Alice's job is not one of them and never moves because of a