Codeforces Team Olympus (violent)

Source: Internet
Author: User

Codeforces Team Olympus (violent)

**************************************** ******************************************************

Original works, from the "Xiaofeng residual month xj" blog, welcome to reprint, reprint please be sure to indicate the source (http://blog.csdn.net/xiaofengcanyuexj ).

For various reasons, there may be many shortcomings. Thank you!

******************************************************* **************************************** **********

A. Team Olympus iadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

The School has 0 of the capital of Berland hasNChildren 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 valueTI:

T I? =? 1, ifI-Th child is good at programming,TI? =? 2, ifI-Th child is good at maths,TI? =? 3, ifI-Th child is good at PE

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

The Team Scientific Decathlon Olympus IAS 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 Olympus IAD? How shoshould the teams be formed for that?

Input

The first line contains integerN(1? ≤?N? ≤? 5000)-the number of children in the school. The second line containsNIntegersT1 ,?T2 ,?...,?TN(1? ≤?TI? ≤? 3), whereTIDescribes the skill ofI-Th child.

Output

In the first line output integerW-The largest possible number of teams.

Then printWLines, 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 1NIn the order of their appearance in the input. Each child must particle 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 valueWEqual to 0.

Sample test (s) Input
71 3 1 3 2 1 2
Output
23 5 26 7 4
Input
42 1 1 2
Output
0

Question:

This question requires that 1, 2, 3 be evenly allocated to three containers as much as possible to ensure that each container contains 1, 2, and 3. Find the maximum number of combinations and output a possible combination. Brute force enumeration is supported! The time complexity is O (n), and the space complexity is O (n ).

Source code:

#include
    
     #include
     
      using namespace std;const int MAXN=5000+100;int per[3][MAXN];int min(int a,int b){return a
      
       




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.