Description

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.

The main school of the capital is located in (sx,sy)(sx,sy)(sx,sy). There are n students attending this school, the i-th of them lives in the house located in (xi,yi). It is possible that some students live in the same house, but no student lives in (sx,sy)(sx,sy)(sx,sy).

After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the iii-th student goes from the school to his house is ∣sx−xi∣+∣sy−yi∣|s_x−x_i|+|s_y−y_i|∣sx​−xi​∣+∣sy​−yi​∣.

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 iii-th student will buy a shawarma if at least one of the shortest paths from the school to the iii

-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).

You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.

Input

The first line contains three integers nnn, sxsxsx, sy(1≤n≤200000,0≤sx,sy≤109)sy (1≤n≤200000, 0≤sx,sy≤10^9)sy(1≤n≤200000,0≤sx,sy≤109) — the number of students and the coordinates of the school, respectively.

Then nnn lines follow. The iii-th of them contains two integers xi,yi(0≤xi,yi≤109)xi, yi (0≤x_i,y_i≤10^9)xi,yi(0≤xi​,yi​≤109) — the location of the house where the iii-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.

Output

The output should consist of two lines. The first of them should contain one integer ccc — the maximum number of students that will buy shawarmas at the tent.

The second line should contain two integers pxp_xpx​ and pyp_ypy​ — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of pxp_xpx​ and pyp_ypy​ should be not less than 000 and not greater than 10910^9109.

题意

给定原点和若干点,定义点到原点距离为∣sx−xi∣+∣sy−yi∣|s_x−x_i|+|s_y−y_i|∣sx​−xi​∣+∣sy​−yi​∣,现在要选择一个位置建造帐篷,若一个点到原点有经过这个帐篷的最短路径,那么就会产生111点贡献。问在哪里建造帐篷能获得的贡献值最大。

思路

很显然,一个点到原点的最短路径可行方案覆盖了以该点和原点为对角顶点的整个矩形。



大概就是这样的一个矩形。因此我有了一个很自然的思路:每次给这个矩形里所有值+1,最后统计答案遍历每个点即可。

打算二维树状数组搞一搞,然后发现值域过大……

正解:这个矩形的某一个顶点是确定的,即原点是确定的,那么一定只有这几种情况:

  1. 点在原点的左上方,那么建筑在原点左一格和原点上一格都可以让该点产生贡献。
  2. 点在原点的左下方,那么建筑在原点左一格和原点下一格都可以让该点产生贡献。
  3. 点在原点的右上方,那么建筑在原点右一格和原点上一格都可以让该点产生贡献。
  4. 点在原点右下方,那么建筑在原点右一格和原点下一格都可以让该点产生贡献。

    也就是说,原点上下左右四个建筑位置一定是最优的。

    归纳一下,得到:

原点左边的所有点都会对建筑在原点左一格的情况产生贡献。

原点右边的所有点都会对建筑在原点右一格的情况产生贡献。

原点上方的所有点都会对建筑在原点上一格的情况产生贡献。

原点下方的所有点都会对建筑在原点上一格的情况产生贡献。



在其他位置建筑的话,肯定都不如这四个点,可以画一下贡献区域感受一下。

Code

#include <cstdio>
using namespace std;
inline char nc()
{
static char buf[1000000],*p1 = buf,*p2 = buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
void read(T &r)
{
static char c; r=0;
for(c=nc();c>'9'||c<'0';c=nc());
for(;c>='0'&&c<='9';r=(r<<1)+(r<<3)+(c^48),c=nc());
}
int n,p,q;
int l,r,top,bottom;
inline int max(const int &a,const int &b){return a>b?a:b;}
int main()
{
read(n);
read(p);
read(q);
int x,y;
for(;n;--n)
{
read(x);
read(y);
if(x < p)
++l;
else if(x > p)
++r;
if(y > q)
++top;
else if(y < q)
++bottom;
}
int maxx = max(l,max(r,max(top,bottom)));
printf("%d\n",maxx);
if(maxx == l)
printf("%d %d",p - 1,q);
else if(maxx == r)
printf("%d %d",p + 1,q);
else if(maxx == top)
printf("%d %d",p,q+1);
else
printf("%d %d",p,q-1);
return 0;
}

[Codeforces #608 div2]1271C Shawarma Tent的更多相关文章

  1. [Codeforces #608 div2]1271D Portals

    Description You play a strategic video game (yeah, we ran out of good problem legends). In this game ...

  2. [Codeforces #608 div2]1272B Blocks

    Description There are nnn blocks arranged in a row and numbered from left to right, starting from on ...

  3. [Codeforces #608 div2]1271A Suits

    Description A new delivery of clothing has arrived today to the clothing store. This delivery consis ...

  4. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  5. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  6. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  7. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  8. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  9. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

随机推荐

  1. C:变量的声明与定义

    声明变量不需要建立存储空间,如:extern int a; 定义变量需要建立存储空间,如:int b; #include <stdio.h> int main() { //extern 关 ...

  2. Django安装数据库MySQLdb

    在使用Django搭建与树莓派智能终端时,使用mysql作为数据库管理,遇到如下问题: django.core.exceptions.ImproperlyConfigured: Error loadi ...

  3. 转发-[原创]ASR1K 在Rommon导入IOS-XE启动

    在相对较老的设备平台可以通过在rommon下使用以下命令导入IOS. rommon 1 > IP_ADDRESS=192.168.1.2rommon 2 > IP_SUBNET_MASK= ...

  4. 2019年4月22日A股暴跌行情思考

    2019年4月22日A股暴跌行情思考 原因:股指期货松绑 盘面:小幅高开,单边下跌 操作: 总结: 股指期货松绑,周末媒体YY大盘暴涨,不排除空头故意借助媒体来诱多,然开盘后暴跌. 预期过于一致时,需 ...

  5. SpringMvc 项目配置

    spring-mvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&quo ...

  6. nyoj 67

    三角形面积 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 给你三个点,表示一个三角形的三个顶点,现你的任务是求出该三角形的面积   输入 每行是一组测试数据,有6个 ...

  7. Linux 命令中 find 和 xargs 命令的用法

    find 命令(一) find 命令主要作用是沿着文件层次结构向下遍历,匹配符合条件的文件,并执行相应的操作.Linux 下 find 命令提供了相当多的查找条件,功能很强大,对应的学习难度也比较大. ...

  8. php 低版本不能使用php 命令,创建软链接

      ln -s /usr/local/php5/bin/php /usr/bin/php php 低版本不能使用php 命令,创建软链接   phpize 依赖于 phpcli 模式 所以php命令必 ...

  9. php 高级 PHP的垃圾回收机制

    PHP可以自动进行内存管理,清楚不再需要的对象.PHP使用了引用计数这种单纯的垃圾回收机制.每个对象都内含一个引用计数器,每个reference链接到对象,计数器加1,当reference离开生存空间 ...

  10. 设计模式课程 设计模式精讲 3-3 开闭原则 coding

    1 课程讲解 1.1 开闭原则定义 1.2 不重要内容 2 代码coding 2.1 基类 2.2 需求:打印出原价和折扣后的价格.(接口不应该随意变化,面向接口编程) 1 课程讲解 1.1 开闭原则 ...