logo AlgoBeat OnlineJudge
登录 注册

#212855. [NERC 2022] Easy Assembly

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Emma loves playing with blocks. She has several cubic blocks of the same size that are numbered with integers written on them. She assembles towers from those blocks by stacking them vertically.

A configuration of her game is a set of towers that she has assembled from the blocks. Emma can perform two kinds of operations on a configuration of towers:

  • any tower with more than one block in it by taking any number of blocks from the top of the tower and moving them to a new tower keeping their order, so that the top block of the old tower becomes the top block of the new tower. As a result of this operation, the number of towers increases by one.

  • any two towers by moving blocks from one tower on top of the other tower in the same order. As a result of this operation, the number of towers decreases by one.

Emma wants to stack all the blocks into a single tower so that all blocks come in order sorted by the numbers --- from the block with the minimal number at the top to the block with the maximal number at the bottom. Emma wants to do as little of splitting and combining operations as possible. Your task is to find the minimal number of operations she has to make and output how many splits and combines are needed.

输入格式

The first line of the input file contains an integer () --- the number of towers in the initial configuration. Next lines describe towers. Each tower is described by a line that starts with the number (; ) --- the number of blocks in the tower, followed by numbers () --- numbers written on the blocks in the -th tower, listed from top to bottom. All block numbers listed in the input are different.

输出格式

Output a line with two integers and --- the number of split and combine operations Emma should make to get a single tower with blocks sorted by their numbers, so that the total number of operations is minimized.

样例

样例输入 1

2
3 3 5 8
2 9 2

样例输出 1

1 2

数据范围与提示

The example needs the following operations (1 split and 2 combines).