codeforces-scrape

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

799B.md (2569B)


      1 Source: https://codeforces.com/problemset/problem/799/B
      2 
      3 B. T-shirt buying
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and *b**i* are integers from 1 to 3.
     22 
     23 *m* buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the *j*-th buyer we know his favorite color *c**j*.
     24 
     25 A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.
     26 
     27 You are to compute the prices each buyer will pay for t-shirts.
     28 
     29 Input
     30 
     31 The first line contains single integer *n* (1 ≤ *n* ≤ 200 000) — the number of t-shirts.
     32 
     33 The following line contains sequence of integers *p*1, *p*2, ..., *p**n* (1 ≤ *p**i* ≤ 1 000 000 000), where *p**i* equals to the price of the *i*-th t-shirt.
     34 
     35 The following line contains sequence of integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 3), where *a**i* equals to the front color of the *i*-th t-shirt.
     36 
     37 The following line contains sequence of integers *b*1, *b*2, ..., *b**n* (1 ≤ *b**i* ≤ 3), where *b**i* equals to the back color of the *i*-th t-shirt.
     38 
     39 The next line contains single integer *m* (1 ≤ *m* ≤ 200 000) — the number of buyers.
     40 
     41 The following line contains sequence *c*1, *c*2, ..., *c**m* (1 ≤ *c**j* ≤ 3), where *c**j* equals to the favorite color of the *j*-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.
     42 
     43 Output
     44 
     45 Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1.
     46 
     47 Examples
     48 
     49 Input
     50 
     51 ```
     52 5  
     53 300 200 400 500 911  
     54 1 2 1 2 3  
     55 2 1 3 2 1  
     56 6  
     57 2 3 1 2 1 1
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 200 400 300 500 911 -1
     64 ```
     65 
     66 Input
     67 
     68 ```
     69 2  
     70 1000000000 1  
     71 1 1  
     72 1 2  
     73 2  
     74 2 1
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 1 1000000000
     81 ```