codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

28A.md (2298B)


      1 Source: https://codeforces.com/problemset/problem/28/A
      2 
      3 A. Bender Problem
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Robot Bender decided to make Fray a birthday present. He drove *n* nails and numbered them from 1 to *n* in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.
     22 
     23 Help Bender to solve this difficult task.
     24 
     25 Input
     26 
     27 The first line contains two positive integers *n* and *m* (4 ≤ *n* ≤ 500, 2 ≤ *m* ≤ 500, *n* is even) — the amount of nails and the amount of rods. *i*-th of the following *n* lines contains a pair of integers, denoting the coordinates of the *i*-th nail. Nails should be connected in the same order as they are given in the input. The last line contains *m* integers — the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.
     28 
     29 Output
     30 
     31 If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output *n* numbers — *i*-th of them should be the number of rod, which fold place is attached to the *i*-th nail, or -1, if there is no such rod.
     32 
     33 If there are multiple solutions, print any of them.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 4 2  
     41 0 0  
     42 0 2  
     43 2 2  
     44 2 0  
     45 4 4
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 YES  
     52 1 -1 2 -1
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 6 3  
     59 0 0  
     60 1 0  
     61 1 1  
     62 2 1  
     63 2 2  
     64 0 2  
     65 3 2 3
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 YES  
     72 1 -1 2 -1 3 -1
     73 ```
     74 
     75 Input
     76 
     77 ```
     78 6 3  
     79 0 0  
     80 1 0  
     81 1 1  
     82 2 1  
     83 2 2  
     84 0 2  
     85 2 2 3
     86 ```
     87 
     88 Output
     89 
     90 ```
     91 NO
     92 ```