CF490A.Team Olympiad

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value t__i:

  • t__i = 1, if the i-th child is good at programming,
  • t__i = 2, if the i-th child is good at maths,
  • t__i = 3, if the i-th child is good at PE

Each child happens to be good at exactly one of these three subjects.

The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.

What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?

首都贝尔兰市第0号学校有 nn 名学生在此就读。该校所有学生均天赋异禀:其中一些擅长编程,一些擅长数学,另一些则擅长体育(PE)。因此,对每位学生 ii,我们已知一个值 tit_i:

  • ti=1t_i = 1,表示第 ii 名学生擅长编程;
  • ti=2t_i = 2,表示第 ii 名学生擅长数学;
  • ti=3t_i = 3,表示第 ii 名学生擅长体育。

每位学生恰好擅长上述三门学科中的一门。

“团队科学十项全能奥林匹克竞赛”要求每支参赛队由三名学生组成。校方教师决定:每支队伍必须由三名擅长不同学科的学生构成,即每支队伍须恰好包含一名数学家、一名程序员和一名运动员。当然,每名学生至多只能加入一支队伍。

问:该校最多能派出多少支队伍参加该奥林匹克竞赛?又应如何组队才能达到这一最大数目?

输入格式

The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ 3), where t__i describes the skill of the i-th child.

第一行包含一个整数 nn(1≤n≤50001 \leq n \leq 5000)—— 学校中儿童的数量。
第二行包含 nn 个整数 t1,t2,…,tnt_1, t_2, \dots, t_n(1≤ti≤31 \leq t_i \leq 3),其中 tit_i 表示第 ii 个儿童的技能等级。

输出格式

In the first line output integer w — the largest possible number of teams.

Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.

If no teams can be compiled, print the only line with value w equal to 0.

第一行输出整数 ww —— 最多可以组成的队伍数量。

随后输出 ww 行,每行包含三个数字。每个三元组表示组成一支队伍的三个孩子的编号。你可以以任意顺序输出各支队伍,以及每个三元组内的数字顺序。孩子按输入中出现的顺序编号为 11 到 nn。每个孩子至多只能参加一支队伍。若存在多种解法,输出任意一种即可。

若无法组成任何队伍,则仅输出一行,其值 w=0w = 0。

输入输出样例

  • 输入#1

    7
    1 3 1 3 2 1 2

    输出#1

    2
    3 5 2
    6 7 4
  • 输入#2

    4
    2 1 1 2

    输出#2

    0

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

首页