308274: CF1491I. Ruler Of The Zoo

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Ruler Of The Zoo

题意翻译

感谢 $\color{black}\text{s}\color{red}\text{yksykCCC}$ 做出的贡献。 在认识到动物园管理员是一只小黄鸭之后,这些动物推翻了动物园管理员,它们现在要通过以下方法来决定新的动物园之王。 最初,动物 $0$ 是大王,动物 $1, 2, \cdots, n - 1$ 会依次成一队,动物 $0$ 站在最前面。每次,队首的动物将会与当前的大王进行一次格斗,力量更大的动物将会胜出这次格斗。胜出者成为新的大王,失败者加入队列的末尾。 **连续胜出 $3$ 次**的动物将会成为动物园之王。每个动物的力量取决于他连续胜出了几次。动物 $i$ 如果连续胜出了 $0$ 场,力量将会是 $A_i$;连续胜出了 $1$ 场,力量将会是 $B_i$;连续胜出了 $2$ 场,力量将会是 $C_i$。最初,每个动物都只连续胜出了 $0$ 场。 **对于每个动物,保证 $A_i > B_i$,$C_i > B_i$**。同时,所有动物的 $A_i, B_i, C_i$ 的值保证**互不相同**。 显而易见的,非大王的动物力量为 $A_i$。大王的力量一般都是 $B_i$ 或 $C_i$,除非是第一轮,大王(动物 $0$)的力量为 $A_i$。 新的动物园之王将会是哪个动物,经过了多少次格斗?或者永远无法选出新的大王?

题目描述

After realizing that Zookeeper is just a duck, the animals have overthrown Zookeeper. They now have to decide a new ruler among themselves through a fighting tournament of the following format: Initially, animal $ 0 $ is king, while everyone else queues up with animal $ 1 $ at the front of the queue and animal $ n-1 $ at the back. The animal at the front of the queue will challenge the king to a fight, and the animal with greater strength will win the fight. The winner will become king, while the loser joins the back of the queue. An animal who wins $ 3 $ times consecutively will be crowned ruler for the whole zoo. The strength of each animal depends on how many consecutive fights he won. Animal $ i $ has strength $ A_i $ with $ 0 $ consecutive win, $ B_i $ with $ 1 $ consecutive win, and $ C_i $ with $ 2 $ consecutive wins. Initially, everyone has $ 0 $ consecutive win. For all animals, $ A_i > B_i $ and $ C_i > B_i $ . Also, the values of $ A_i $ , $ B_i $ , $ C_i $ are distinct (all $ 3n $ values are pairwise different). In other words, an animal who is not a king has strength $ A_i $ . A king usually has a strength of $ B_i $ or $ C_i $ . The exception is on the first turn, the first king (animal $ 0 $ ) has strength $ A_i $ . Who is the new ruler, and after how many fights? Or will it end up that animals fight forever with no one ending up as ruler?

输入输出格式

输入格式


The first line contains one integer $ n $ ( $ 4 \leq n \leq 6000 $ ) — number of the animals. $ i $ -th of the next $ n $ lines contains $ 3 $ integers $ A_i $ , $ B_i $ and $ C_i $ ( $ 0 \leq A_i, B_i, C_i \leq 10^9 $ ). It is guaranteed that $ A_i > B_i $ and $ C_i > B_i $ , and that all values of $ A_i $ , $ B_i $ and $ C_i $ are distinct.

输出格式


Output two integers in a single line. The first is the index of the animal that will become ruler, and the second is the number of fights passed until some animal becomes the ruler. If the animals will fight for infinitely long, output -1 -1 instead.

输入输出样例

输入样例 #1

4
5 1 2
10 8 11
9 0 3
7 4 6

输出样例 #1

-1 -1

输入样例 #2

5
11 7 12
8 6 14
2 1 10
13 0 9
5 3 4

输出样例 #2

1 7

说明

The following describes the sequence of events for the second sample. Note that in fight $ 1 $ , the king (animal $ 0 $ ) has strength $ A_0 $ . The tournament ends at fight $ 7 $ as animal $ 1 $ wins fight $ 5 $ , $ 6 $ and $ 7 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1491I/7b13e4dcb78655ebc8cd1c3836535a03ee25025a.png)

Input

题意翻译

感谢 $\color{black}\text{s}\color{red}\text{yksykCCC}$ 做出的贡献。 在认识到动物园管理员是一只小黄鸭之后,这些动物推翻了动物园管理员,它们现在要通过以下方法来决定新的动物园之王。 最初,动物 $0$ 是大王,动物 $1, 2, \cdots, n - 1$ 会依次成一队,动物 $0$ 站在最前面。每次,队首的动物将会与当前的大王进行一次格斗,力量更大的动物将会胜出这次格斗。胜出者成为新的大王,失败者加入队列的末尾。 **连续胜出 $3$ 次**的动物将会成为动物园之王。每个动物的力量取决于他连续胜出了几次。动物 $i$ 如果连续胜出了 $0$ 场,力量将会是 $A_i$;连续胜出了 $1$ 场,力量将会是 $B_i$;连续胜出了 $2$ 场,力量将会是 $C_i$。最初,每个动物都只连续胜出了 $0$ 场。 **对于每个动物,保证 $A_i > B_i$,$C_i > B_i$**。同时,所有动物的 $A_i, B_i, C_i$ 的值保证**互不相同**。 显而易见的,非大王的动物力量为 $A_i$。大王的力量一般都是 $B_i$ 或 $C_i$,除非是第一轮,大王(动物 $0$)的力量为 $A_i$。 新的动物园之王将会是哪个动物,经过了多少次格斗?或者永远无法选出新的大王?

加入题单

算法标签: