codeforces-scrape

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

1075B.md (3101B)


      1 Source: https://codeforces.com/problemset/problem/1075/B
      2 
      3 B. Taxi drivers and Lyft
      4 
      5 time limit per test
      6 
      7 1 second
      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 Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.
     22 
     23 Lyft has become so popular so that it is now used by all $m$ taxi drivers in the city, who every day transport the rest of the city residents — $n$ riders.
     24 
     25 Each resident (including taxi drivers) of Palo-Alto lives in its unique location (there is no such pair of residents that their coordinates are the same).
     26 
     27 The Lyft system is very clever: when a rider calls a taxi, his call does not go to all taxi drivers, but only to the one that is the closest to that person. If there are multiple ones with the same distance, then to taxi driver with a smaller coordinate is selected.
     28 
     29 But one morning the taxi drivers wondered: how many riders are there that would call the given taxi driver if they were the first to order a taxi on that day? In other words, you need to find for each taxi driver $i$ the number $a_{i}$ — the number of riders that would call the $i$-th taxi driver when all drivers and riders are at their home?
     30 
     31 The taxi driver can neither transport himself nor other taxi drivers.
     32 
     33 Input
     34 
     35 The first line contains two integers $n$ and $m$ ($1 \le n,m \le 10^5$) — number of riders and taxi drivers.
     36 
     37 The second line contains $n + m$ integers $x_1, x_2, \ldots, x_{n+m}$ ($1 \le x_1 \lt x_2 \lt \ldots \lt x_{n+m} \le 10^9$), where $x_i$ is the coordinate where the $i$-th resident lives.
     38 
     39 The third line contains $n + m$ integers $t_1, t_2, \ldots, t_{n+m}$ ($0 \le t_i \le 1$). If $t_i = 1$, then the $i$-th resident is a taxi driver, otherwise $t_i = 0$.
     40 
     41 It is guaranteed that the number of $i$ such that $t_i = 1$ is equal to $m$.
     42 
     43 Output
     44 
     45 Print $m$ integers $a_1, a_2, \ldots, a_{m}$, where $a_i$ is the answer for the $i$-th taxi driver. The taxi driver has the number $i$ if among all the taxi drivers he lives in the $i$-th smallest coordinate (see examples for better understanding).
     46 
     47 Examples
     48 
     49 Input
     50 
     51 ```
     52 3 1  
     53 1 2 3 10  
     54 0 0 1 0
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 3
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 3 2  
     67 2 3 4 5 6  
     68 1 0 0 0 1
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 2 1
     75 ```
     76 
     77 Input
     78 
     79 ```
     80 1 4  
     81 2 4 6 10 15  
     82 1 1 1 1 0
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 0 0 0 1
     89 ```
     90 
     91 Note
     92 
     93 In the first example, we have only one taxi driver, which means an order from any of $n$ riders will go to him.
     94 
     95 In the second example, the first taxi driver lives at the point with the coordinate $2$, and the second one lives at the point with the coordinate $6$. Obviously, the nearest taxi driver to the rider who lives on the $3$ coordinate is the first one, and to the rider who lives on the coordinate $5$ is the second one. The rider who lives on the $4$ coordinate has the same distance to the first and the second taxi drivers, but since the first taxi driver has a smaller coordinate, the call from this rider will go to the first taxi driver.
     96 
     97 In the third example, we have one rider and the taxi driver nearest to him is the fourth one.