<\/span><\/h2>\n\n\n\nThe School \u21160 of the capital of Berland has n<\/em> 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<\/em>i<\/em><\/sub>:<\/p>\n\n\n\n\n- t<\/em>i<\/em><\/sub>\u2009=\u20091, if the\u00a0i<\/em>-th child is good at programming,<\/li>\n\n\n\n
- t<\/em>i<\/em><\/sub>\u2009=\u20092, if the\u00a0i<\/em>-th child is good at maths,<\/li>\n\n\n\n
- t<\/em>i<\/em><\/sub>\u2009=\u20093, if the\u00a0i<\/em>-th child is good at PE<\/li>\n<\/ul>\n\n\n\n
Each child happens to be good at exactly one of these three subjects.<\/p>\n\n\n\n
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.<\/p>\n\n\n\n
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?<\/p>\n\n\n\n
<\/div>\n\n\n\n
Input<\/strong><\/p>\n\n\n\nThe first line contains integer\u00a0n<\/em>\u00a0(1\u2009\u2264\u2009n<\/em>\u2009\u2264\u20095000) \u2014 the number of children in the school. The second line contains\u00a0n<\/em>\u00a0integers\u00a0t<\/em>1<\/sub>,\u2009t<\/em>2<\/sub>,\u2009…,\u2009t<\/em>n<\/em><\/sub>\u00a0(1\u2009\u2264\u2009t<\/em>i<\/em><\/sub>\u2009\u2264\u20093), where\u00a0t<\/em>i<\/em><\/sub>\u00a0describes the skill of the\u00a0i<\/em>-th child.<\/p>\n\n\n\n<\/div>\n\n\n\n
Output<\/strong><\/p>\n\n\n\nIn the first line output integer w<\/em> \u2014 the largest possible number of teams.<\/p>\n\n\n\nThen print w<\/em> 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<\/em> 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.<\/p>\n\n\n\nIf no teams can be compiled, print the only line with value\u00a0w<\/em>\u00a0equal to 0.<\/p>\n\n\n\n<\/div>\n\n\n\n
Examples<\/strong><\/p>\n\n\n\nInput<\/td> | 7 1 3 1 3 2 1 2<\/td><\/tr> |
Output<\/td> | 2 3 5 2 6 7 4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<\/div>\n\n\n\n Input<\/td> | 4 2 1 1 2<\/td><\/tr> | Output<\/td> | 0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<\/div>\n\n\n\n
\n\n\n\n <\/span>Solution<\/strong><\/span><\/h2>\n\n\n\nWe can use three List collections to store the indices of children based on their skills.<\/p>\n\n\n\n <\/div>\n\n\n\n <\/span>C# Solution<\/strong><\/span><\/h3>\n\n\n\nSolution1<\/strong><\/p>\n\n\n\nList<int>programming = new List<int>();\nList<int>math = new List<int>();\nList<int>pe = new List<int>();\n\nint n = int.Parse(Console.ReadLine());\nint[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n\nfor(int i=0; i<arr.Length; i++){\n int item = arr[i];\n if(item == 1){\n programming.Add(i+1); \n }\n else if(item ==2){\n math.Add(i+1);\n }\n else{\n pe.Add(i+1);\n }\n}\n\nint min = Math.Min(programming.Count,math.Count);\nmin = Math.Min(min,pe.Count);\n\nConsole.WriteLine(min);\n\nfor(int j=0; j<min; j++){\n string res = $"{programming[j]} {math[j]} {pe[j]}";\n Console.WriteLine(res);\n}<\/code><\/pre><\/div>\n\n\n\n
|
|