codeforces-scrape

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

1271C.md (3016B)


      1 Source: https://codeforces.com/problemset/problem/1271/C
      2 
      3 C. Shawarma Tent
      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 The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.
     22 
     23 The main school of the capital is located in $(s_x, s_y)$. There are $n$ students attending this school, the $i$-th of them lives in the house located in $(x_i, y_i)$. It is possible that some students live in the same house, but no student lives in $(s_x, s_y)$.
     24 
     25 After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the $i$-th student goes from the school to his house is $|s_x - x_i| + |s_y - y_i|$.
     26 
     27 The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the $i$-th student will buy a shawarma if at least one of the shortest paths from the school to the $i$-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).
     28 
     29 You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.
     30 
     31 Input
     32 
     33 The first line contains three integers $n$, $s_x$, $s_y$ ($1 \le n \le 200\,000$, $0 \le s_x, s_y \le 10^{9}$) — the number of students and the coordinates of the school, respectively.
     34 
     35 Then $n$ lines follow. The $i$-th of them contains two integers $x_i$, $y_i$ ($0 \le x_i, y_i \le 10^{9}$) — the location of the house where the $i$-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.
     36 
     37 Output
     38 
     39 The output should consist of two lines. The first of them should contain one integer $c$ — the maximum number of students that will buy shawarmas at the tent.
     40 
     41 The second line should contain two integers $p_x$ and $p_y$ — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of $p_x$ and $p_y$ should be not less than $0$ and not greater than $10^{9}$.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4 3 2
     49 1 3
     50 4 2
     51 5 1
     52 4 1
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 3
     59 4 2
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 3 100 100
     66 0 0
     67 0 0
     68 100 200
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 2
     75 99 100
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 7 10 12
     82 5 6
     83 20 23
     84 15 4
     85 16 5
     86 4 54
     87 12 1
     88 4 15
     89 ```
     90 
     91 Output
     92 
     93 ```
     94 4
     95 10 11
     96 ```
     97 
     98 Note
     99 
    100 In the first example, If we build the shawarma tent in $(4, 2)$, then the students living in $(4, 2)$, $(4, 1)$ and $(5, 1)$ will visit it.
    101 
    102 In the second example, it is possible to build the shawarma tent in $(1, 1)$, then both students living in $(0, 0)$ will visit it.