#C3276. Distributing Tokens Between Alice and Bob

    ID: 46685 Type: Default 1000ms 256MiB

Distributing Tokens Between Alice and Bob

Distributing Tokens Between Alice and Bob

Alice and Bob have a collection of tokens. Alice has tokens of two types: Type A and Type B, and Bob also has tokens of Type A and Type B. Given a target number \(m\) (the total number of tokens to be distributed), determine if it is possible to select tokens from Alice and Bob such that the total number exactly equals \(m\).

If a valid distribution exists, output "YES" along with four non-negative integers \(x, y, p, q\) where:

  • \(x\) is the number of Type A tokens chosen from Alice (\(0 \le x \le a_A\)).
  • \(y\) is the number of Type B tokens chosen from Alice (\(0 \le y \le a_B\)).
  • \(p\) is the number of Type A tokens chosen from Bob (\(0 \le p \le b_A\)).
  • \(q\) is the number of Type B tokens chosen from Bob (\(0 \le q \le b_B\)).

These numbers must satisfy:

[ x + y + p + q = m ]

If no such selection exists, output "NO".

Note that if there exist multiple valid distributions, your program can output any one of them.

inputFormat

The input consists of a single line containing five integers separated by spaces:

  • \(m\): The total number of tokens to be distributed.
  • \(a_A\): The number of Type A tokens Alice has.
  • \(a_B\): The number of Type B tokens Alice has.
  • \(b_A\): The number of Type A tokens Bob has.
  • \(b_B\): The number of Type B tokens Bob has.

All values are integers.

outputFormat

If a valid distribution exists, output two lines. The first line should contain the word "YES". The second line should contain four space-separated integers \(x, y, p, q\) corresponding to a valid token distribution.

If no valid distribution exists, output a single line with "NO".

## sample
10 5 3 4 6
YES

0 0 4 6

</p>