EavEva - Eavesdropper Evasion
Dữ liệu vào: Standard input
Dữ liệu ra: Standard output
Giới hạn thời gian: 4.0 giây
Giới hạn bộ nhớ: 512 megabyte
Đăng bởi: smurf

Alice wants to send \(n\) messages to Bob over a communication channel. The \(i\)-th message takes \(t_i\) time steps to send. At each integer time step, Alice can start sending any number of her messages. Once started, a message must be transmitted in its entirety (it cannot be paused and resumed later). Any number of messages can be sent in parallel over the channel without affecting the transmission time of individual messages.

An attacker has the capability to disable the security protocols of the channel for an interval of \(x\) continuous time steps, but only once (i.e., after doing this, they cannot wait a while and then disable it for another \(x\) time steps). While the security is disabled, the attacker is able to listen in, and any message that is sent in its entirety during those \(x\) time steps is considered exposed.

What is the minimum time needed for Alice to send all \(n\) messages to Bob so that at most two messages are exposed, no matter when the attacker chooses to disable the security?

Input:

The first line of input contains the two integers \(n\) and \(x\) \((1 \leq n \leq 20000, 1 \leq x \leq 10000)\), the number of messages Alice wants to send and the number of time steps someone may listen in. This is followed by a line containing \(n\) integers \(t_1, \dots, t_n \)\((1 \leq t_i \leq 10000)\), the number of time steps it takes to transmit each message.

Output:

Output the minimum number of time steps to complete transmission of all \(n\) messages so that at most two of them can be exposed.

Ví dụ

  • input
    6 10
    2 3 4 5 6 7
    output
    16
  • input
    7 6
    9 3 2 3 8 3 3
    output
    11

Figure 1: Left: Illustration of a solution to Sample Input 1. Right: sending the message of length \(4\) a time step earlier would not be a solution, because the three messages of length \(6\)\(4\), and \(3\) would then be exposed to an eavesdropper listening in from time step \(5\) to time step \(15\).

Note: Đừng chép code nha 

Back to Top