CF1271F.Divide The Students

省选/NOI-

通过率:0%

时间限制:8.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Recently a lot of students were enrolled in Berland State University. All students were divided into groups according to their education program. Some groups turned out to be too large to attend lessons in the same auditorium, so these groups should be divided into two subgroups. Your task is to help divide the first-year students of the computer science faculty.

There are tt new groups belonging to this faculty. Students have to attend classes on three different subjects — maths, programming and P. E. All classes are held in different places according to the subject — maths classes are held in auditoriums, programming classes are held in computer labs, and P. E. classes are held in gyms.

Each group should be divided into two subgroups so that there is enough space in every auditorium, lab or gym for all students of the subgroup. For the first subgroup of the ii-th group, maths classes are held in an auditorium with capacity of ai,1a_{i, 1} students; programming classes are held in a lab that accomodates up to bi,1b_{i, 1} students; and P. E. classes are held in a gym having enough place for ci,1c_{i, 1} students. Analogically, the auditorium, lab and gym for the second subgroup can accept no more than ai,2a_{i, 2}, bi,2b_{i, 2} and ci,2c_{i, 2} students, respectively.

As usual, some students skip some classes. Each student considers some number of subjects (from 00 to 33) to be useless — that means, he skips all classes on these subjects (and attends all other classes). This data is given to you as follows — the ii-th group consists of:

  1. di,1d_{i, 1} students which attend all classes;
  2. di,2d_{i, 2} students which attend all classes, except for P. E.;
  3. di,3d_{i, 3} students which attend all classes, except for programming;
  4. di,4d_{i, 4} students which attend only maths classes;
  5. di,5d_{i, 5} students which attend all classes, except for maths;
  6. di,6d_{i, 6} students which attend only programming classes;
  7. di,7d_{i, 7} students which attend only P. E.

There is one more type of students — those who don't attend any classes at all (but they, obviously, don't need any place in auditoriums, labs or gyms, so the number of those students is insignificant in this problem).

Your task is to divide each group into two subgroups so that every auditorium (or lab, or gym) assigned to each subgroup has enough place for all students from this subgroup attending the corresponding classes (if it is possible). Each student of the ii-th group should belong to exactly one subgroup of the ii-th group; it is forbidden to move students between groups.

最近,许多学生被录取进入贝尔兰国立大学。所有学生根据其教育项目被划分到不同的班级。一些班级人数过多,无法在同一个阶梯教室中上课,因此这些班级需要被拆分为两个子班级。你的任务是帮助计算机科学学院的一年级新生进行分班。

计算机科学学院共有 tt 个新班级。学生需修读三门不同课程:数学、编程和体育(P. E.)。所有课程均在对应科目的专用场所进行:数学课在阶梯教室(auditorium)授课,编程课在计算机实验室(lab)授课,体育课在体育馆(gym)授课。

每个班级都必须被划分为两个子班级,使得每个子班级在每类场所(阶梯教室、实验室或体育馆)中均有足够的空间容纳该子班级中所有参加对应课程的学生。对于第 ii 个班级的第一个子班级而言:其数学课在容量为 ai,1a_{i, 1} 名学生的阶梯教室中进行;编程课在最多容纳 bi,1b_{i, 1} 名学生的实验室中进行;体育课在可容纳 ci,1c_{i, 1} 名学生的体育馆中进行。类似地,第二个子班级所分配的阶梯教室、实验室和体育馆的容量上限分别为 ai,2a_{i, 2}、bi,2b_{i, 2} 和 ci,2c_{i, 2}。

和往常一样,部分学生会缺席某些课程。每名学生认为若干门课程(0 至 3 门)“毫无用处”——即他将缺席这些课程的所有课时(而参加其余所有课程)。该信息以如下方式给出:第 ii 个班级由以下几类学生组成:

  1. di,1d_{i, 1} 名学生参加全部课程;
  2. di,2d_{i, 2} 名学生除体育课外,其余课程均参加;
  3. di,3d_{i, 3} 名学生除编程课外,其余课程均参加;
  4. di,4d_{i, 4} 名学生仅参加数学课;
  5. di,5d_{i, 5} 名学生除数学课外,其余课程均参加;
  6. di,6d_{i, 6} 名学生仅参加编程课;
  7. di,7d_{i, 7} 名学生仅参加体育课。

还存在一类学生——完全不参加任何课程的学生(但显然他们无需占用阶梯教室、实验室或体育馆的空间,因此这类学生的人数在本题中可忽略不计)。

你的任务是将每个班级划分为两个子班级,使得每个子班级所分配的每类场所(阶梯教室、实验室或体育馆)均有足够空间容纳该子班级中实际参加对应课程的所有学生(若可行)。第 ii 个班级中的每名学生必须且仅能属于该班级的两个子班级之一;禁止跨班级调动学生。

输入格式

The first line contains one integer tt (1≤t≤3001 \le t \le 300) — the number of groups.

Then the descriptions of groups follow. The description of the ii-th group consists of three lines:

  • the first line contains three integers ai,1a_{i, 1}, bi,1b_{i, 1} and ci,1c_{i, 1} (1≤ai,1,bi,1,ci,1≤30001 \le a_{i, 1}, b_{i, 1}, c_{i, 1} \le 3000) — the capacity of the auditorium, lab and gym assigned to the first subgroup of the ii-th group, respectively;
  • the second line contains three integers ai,2a_{i, 2}, bi,2b_{i, 2} and ci,2c_{i, 2} (1≤ai,2,bi,2,ci,2≤30001 \le a_{i, 2}, b_{i, 2}, c_{i, 2} \le 3000) — the capacity of the auditorium, lab and gym assigned to the second subgroup of the ii-th group, respectively;
  • the third line contains integers di,1d_{i, 1}, di,2d_{i, 2}, ..., di,7d_{i, 7} (0≤di,j≤30000 \le d_{i, j} \le 3000) — the number of students belonging to each of the seven aforementioned types in the ii-th group. It is not guaranteed that the sum of these values is positive — a group can consist entirely of students that don't attend classes at all.

It is guaranteed that the total number of students in all groups is not greater than 30003000.

第一行包含一个整数 tt(1≤t≤3001 \le t \le 300)—— 组数。

接下来是各组的描述。第 ii 组的描述由三行组成:

  • 第一行包含三个整数 ai,1a_{i, 1}、bi,1b_{i, 1} 和 ci,1c_{i, 1}(1≤ai,1,bi,1,ci,1≤30001 \le a_{i, 1}, b_{i, 1}, c_{i, 1} \le 3000)—— 分别表示分配给第 ii 组第一个子组的礼堂、实验室和健身房的容量;
  • 第二行包含三个整数 ai,2a_{i, 2}、bi,2b_{i, 2} 和 ci,2c_{i, 2}(1≤ai,2,bi,2,ci,2≤30001 \le a_{i, 2}, b_{i, 2}, c_{i, 2} \le 3000)—— 分别表示分配给第 ii 组第二个子组的礼堂、实验室和健身房的容量;
  • 第三行包含整数 di,1d_{i, 1}、di,2d_{i, 2}、…、di,7d_{i, 7}(0≤di,j≤30000 \le d_{i, j} \le 3000)—— 表示第 ii 组中属于前述七种类型的学生人数。这些数值之和不一定为正数——某组可能完全由不参加任何课程的学生组成。

保证所有组中的学生总数不超过 30003000。

输出格式

For each group, print the result of its division as follows:

  • if it is impossible to divide the group, print one integer −1-1;
  • otherwise print seven integers fi,1f_{i, 1}, fi,2f_{i, 2}, ..., fi,7f_{i, 7} (0≤fi,j≤di,j0 \le f_{i, j} \le d_{i, j}) — the number of students the first, second, ..., seventh type in the first subgroup of the ii-th group (all other students will be assigned to the second subgroup). If there are multiple answers, print any of them.

对每组,按如下方式输出其划分结果:

  • 若该组无法划分,则输出一个整数 −1-1;
  • 否则输出七个整数 fi,1f_{i, 1}、fi,2f_{i, 2}、…、fi,7f_{i, 7}(满足 0≤fi,j≤di,j0 \le f_{i, j} \le d_{i, j}),分别表示第 ii 组的第一个子组中第一、第二、…、第七类学生的数量(其余所有学生将被分配至第二个子组)。若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    3
    9 4 13
    1 10 3
    1 2 3 4 5 6 7
    9 4 13
    1 10 3
    2 1 3 4 5 6 7
    1 2 3
    4 5 6
    0 0 0 0 0 0 0

    输出#1

    1 1 3 4 2 0 7
    -1
    0 0 0 0 0 0 0

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

首页