# PTA 一 水果忍者

2010年风靡全球的“水果忍者”游戏，想必大家肯定都玩过吧？（没玩过也没关系啦~）在游戏当中，画面里会随机地弹射出一系列的水果与炸弹，玩家尽可能砍掉所有的水果而避免砍中炸弹，就可以完成游戏规定的任务。如果玩家可以一刀砍下画面当中一连串的水果，则会有额外的奖励，如图1所示。

### 输入样例：

5
-30 -52 -84
38 22 -49
-99 -22 -99
48 59 -18
-36 -50 -72


### 输出样例：

-99 -99 -30 -52

#include<stdio.h>
#include<algorithm>
using namespace std;

int N;

struct Point
{
int x, y;
}top[10000], down[10000];
int stop[10000], sdown[10000];

bool judgeT(Point a, Point b, Point c) {
return 1ll*(b.y - a.y)*(c.x - b.x) > 1ll*(b.x - a.x)*(c.y - b.y);
}

bool judgeD(Point a, Point b, Point c) {
return 1ll*(b.y - a.y)*(c.x - b.x) < 1ll*(b.x - a.x)*(c.y - b.y);
}

int compare(const void * a, const void* b) {
Point *ap = (Point*)(a), *bp = (Point*)(b);
if (ap->x < bp->x || (ap->x == bp->x&&ap->y < bp->y)) return -1;
return 1;
}

int main() {
scanf("%d", &N);
int i;
int x, y1, y2;
for (i = 0; i<N; i++) {
scanf("%d%d%d", &x, &y1, &y2);
top[i].x = down[i].x = x;
top[i].y = y1;
down[i].y = y2;
}
qsort(top, N,sizeof(Point), compare);
qsort(down, N, sizeof(Point), compare);
int xp = 0, nt = N;
for (i = 1; i < N; i++) {
if (top[i].x == top[xp].x) {
top[i].x = 100000000;
top[xp].y = min(top[i].y, top[xp].y);
nt--;
}
else xp = i;
}
xp = 0;
for (i = 1; i < N; i++) {
if (down[i].x == down[xp].x) {
down[i].x = 100000000;
down[xp].y = max(down[i].y, down[xp].y);
}
else xp = i;
}
qsort(top, N, sizeof(Point), compare);
qsort(down, N, sizeof(Point), compare);
N = nt;
if (N == 1) {
printf("%d %d %d %d\n", x, y1, x, y2);
return 0;
}
int tpre = 0, dpre = 0;
for (i = 0; i < N; i++) {
while (tpre >= 2 && judgeT(top[stop[tpre - 2]], top[stop[tpre - 1]], top[i])) tpre--;
stop[tpre++] = i;
while (dpre >= 2 && judgeD(down[sdown[dpre - 2]], down[sdown[dpre - 1]], down[i])) dpre--;
sdown[dpre++] = i;
}
int j;
for (i = 0; i < tpre - 1; i++) {
for (j = 0; j < dpre; j++)
if (judgeT(top[stop[i]], down[sdown[j]], top[stop[i + 1]])) break;
if (j == dpre)
break;
}
Point left, right;
if (i == tpre - 1) {
for (i = 0; i < dpre - 1; i++) {
for (j = 0; j < tpre; j++)
if (judgeD(down[sdown[i]], top[stop[j]], down[sdown[i + 1]])) break;
if (j == tpre)
break;
}
left = down[sdown[i]];
right = down[sdown[i + 1]];
}
else {
left = top[stop[i]];
right = top[stop[i + 1]];
}
printf("%d %d %d %d\n", left.x, left.y, right.x, right.y);
return 0;
}