Robot Project

Interview

Time limit5sMemory limit256 MB

Summary
Given a target length and up to a million rod lengths, find two rods summing exactly to the target with the maximum length difference, or report impossibility.
Level

Medium4 of 10

Topics
Two pointers, Sorting, Array
Solved
No attempts yet

Problem

Sang-geun and Sun-young are building a robot for a school assignment. While building it, they realize they need exactly two LEGO pieces to plug a hole in the robot.

The hole is xx centimeters wide, and the lengths of the two pieces placed into the hole must sum to exactly the width of the hole. If they do not match exactly, the robot breaks during the demonstration and the two of them receive an F. The hole must always be plugged with two pieces.

They have already measured the length of every LEGO piece in the physics lab precisely. Write a program that finds two pieces that plug the hole perfectly.

Input

The input consists of several test cases and is processed until end of file.

The first line of each test case contains the hole width xx (1≤x≤201 \le x \le 20, xx is an integer) in centimeters.

The second line contains the number of LEGO pieces nn (0≤n≤10000000 \le n \le 1000000).

Each of the next nn lines contains the length ℓ\ell of one LEGO piece. ℓ\ell is a positive integer given in nanometers, and no piece is longer than 1010 centimeters (100000000100000000 nanometers).

(One centimeter equals 1000000010000000 nanometers.)

Output

Print one line for each test case. If there are no two pieces that plug the hole perfectly, print danger. Otherwise print yes ℓ1 ℓ2, where ℓ1≤ℓ2\ell_1 \le \ell_2.

If several choices of two pieces are possible, print the one for which ∣ℓ1−ℓ2∣|\ell_1 - \ell_2| is largest.

Examples7

  1. Example 1

    Input
    1
    4
    9999998
    1
    2
    9999999
    
    Expected output
    yes 1 9999999
    
  2. Example 2

    Input
    1
    3
    5000000
    3000000
    1
    
    Expected output
    danger
    
  3. Example 3

    Input
    5
    0
    
    Expected output
    danger
    
  4. Example 4

    Input
    2
    3
    15000000
    5000000
    7000000
    
    Expected output
    yes 5000000 15000000
    
  5. Example 5

    Input
    2
    2
    10000000
    10000000
    
    Expected output
    yes 10000000 10000000
    
  6. Example 6

    Input
    2
    2
    10000000
    3000000
    
    Expected output
    danger
    
  7. Example 7

    Input
    1
    6
    1
    9999999
    2
    9999998
    4000000
    6000000
    
    Expected output
    yes 1 9999999