CF1607H.Banquet Preparations 2

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The chef has cooked nn dishes yet again: the ii-th dish consists of aia_i grams of fish and bib_i grams of meat.

Banquet organizers consider two dishes ii and jj equal if ai=aja_i=a_j and bi=bjb_i=b_j at the same time.

The banquet organizers estimate the variety of nn dishes as follows. The variety of a set of dishes is equal to the number of different dishes in it. The less variety is, the better.

In order to reduce the variety, a taster was invited. He will eat exactly mim_i grams of food from each dish. For each dish, the taster determines separately how much fish and how much meat he will eat. The only condition is that he will eat exactly mim_i grams of the ii-th dish in total.

Determine how much of what type of food the taster should eat from each dish so that the value of variety is the minimum possible. If there are several correct answers, you may output any of them.

厨师再次烹制了 nn 道菜肴:第 ii 道菜肴由 aia_i 克鱼肉和 bib_i 克猪肉组成。

宴会组织者认为两道菜肴 ii 和 jj 相等,当且仅当同时满足 ai=aja_i = a_j 且 bi=bjb_i = b_j。

宴会组织者按如下方式评估这 nn 道菜肴的多样性:一道菜肴集合的多样性等于其中互不相同的菜肴数量。多样性越小越好。

为降低多样性,主办方邀请了一位品鉴师。他将从每道菜肴中恰好吃掉 mim_i 克食物。对于每道菜肴,品鉴师可自行决定分别吃掉多少克鱼肉和多少克猪肉,唯一约束是:他从第 ii 道菜肴中吃掉的食物总质量必须恰好为 mim_i 克。

请确定品鉴师应从每道菜肴中分别吃掉多少克鱼肉和多少克猪肉,使得最终的多样性达到最小可能值。若存在多种正确方案,输出任意一种即可。

输入格式

The first line of input data contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

Each test case's description is preceded by a blank line. Next comes a line that contains an integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the number of dishes. Then follows nn lines, ii-th of which contains three integers aia_i, bib_i and mim_i (0≤ai,bi≤1060 \leq a_i, b_i \le 10^6; 0≤mi≤ai+bi0 \le m_i \le a_i+b_i) — the mass of fish in ii-th dish, the mass of meat in ii-th dish and how many grams in total the taster should eat in ii-th dish.

The sum of all nn values for all input data sets in the test does not exceed 2⋅1052 \cdot 10^5.

输入数据的第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。

每个测试用例的描述前均有一个空行。接下来是一行,包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示菜肴的数量。随后是 nn 行,其中第 ii 行包含三个整数 aia_i、bib_i 和 mim_i(0≤ai,bi≤1060 \leq a_i, b_i \le 10^6;0≤mi≤ai+bi0 \le m_i \le a_i+b_i),分别表示第 ii 道菜中鱼的质量、肉的质量,以及品鉴师在第 ii 道菜中应食用的总克数。

所有测试数据中各 nn 值的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print on the first line the minimum value of variety that can be achieved by eating exactly mim_i grams of food (for all ii from 11 to nn) from a dish ii.

Then print nn lines that describe a way to do this: the ii-th line should contain two integers xix_i and yiy_i (0≤xi≤ai0 \leq x_i \leq a_i; 0≤yi≤bi0 \leq y_i \leq b_i; xi+yi=mix_i+y_i=m_i), where xix_i is how many grams of fish the taster should eat from ii-th dish, and yiy_i is how many grams of meat.

If there are several ways to achieve a minimum balance, print any of them.

对于每个测试用例,在第一行输出:从第 ii 道菜(ii 从 11 到 nn)中恰好食用 mim_i 克食物所能达到的最小“多样性”值。

然后输出 nn 行,描述一种达成该最小值的方法:第 ii 行应包含两个整数 xix_i 和 yiy_i(满足 0≤xi≤ai0 \leq x_i \leq a_i;0≤yi≤bi0 \leq y_i \leq b_i;且 xi+yi=mix_i + y_i = m_i),其中 xix_i 表示品鉴者应从第 ii 道菜中食用的鱼肉克数,yiy_i 表示应食用的猪肉克数。

若存在多种方案可达成该最小“多样性”,输出任意一种即可。

输入输出样例

  • 输入#1

    5
    
    3
    10 10 2
    9 9 0
    10 9 1
    
    2
    3 4 1
    5 1 2
    
    3
    7 2 5
    6 5 4
    5 5 6
    
    1
    13 42 50
    
    5
    5 7 12
    3 1 4
    7 3 7
    0 0 0
    4 1 5

    输出#1

    1
    1 1
    0 0
    1 0
    2
    0 1
    1 1
    2
    3 2
    0 4
    1 5
    1
    8 42
    2
    5 7
    3 1
    4 3
    0 0
    4 1

输入解题思路,AI测评打分。不知道怎么写?

首页