#C1067. Round-Robin Task Scheduling

    ID: 39900 Type: Default 1000ms 256MiB

Round-Robin Task Scheduling

Round-Robin Task Scheduling

You are given N friends, each with a specified energy level which indicates the maximum number of tasks they can perform. The friends take turns performing tasks in a round-robin fashion. However, the team cannot complete more than T tasks overall.

The objective is to determine the maximum number of tasks that can be completed. Formally, if the energy levels are given by \(E_1, E_2, \dots, E_N\), and \(T\) is the total task limit, the result is:

[ \min\Bigl(\sum_{i=1}^{N}E_i,\ T\Bigr) ]

For instance, if there are 3 friends with energy levels [5, 2, 3] and \(T=10\), the maximum number of completed tasks will be 10 since \(\min(5+2+3, 10)=10\). On the other hand, if there are 4 friends each with an energy level of 1 and \(T=5\), the maximum number of completed tasks is 4 because \(\min(1+1+1+1, 5)=4\>.

inputFormat

The input is provided via standard input (stdin) and consists of three lines:

  1. The first line contains a single integer N, representing the number of friends.
  2. The second line contains N space-separated integers which denote the energy levels of each friend.
  3. The third line contains a single integer T, representing the total number of tasks available.

outputFormat

Output a single integer to standard output (stdout) representing the maximum number of tasks that can be completed following the round-robin order and the given energy constraints.

## sample
3
5 2 3
10
10