Codeforces 490 - A problem solution

A. Team Olympiad
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

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 ti:
  • ti = 1, if the i-th child is good at programming,
  • ti = 2, if the i-th child is good at maths,
  • ti = 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?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn(1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
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.
Examples
input
7
1 3 1 3 2 1 2
output
2
3 5 2
6 7 4

input
4
2 1 1 2
output
0

Problem link : https://codeforces.com/problemset/problem/490/A

Solution:

  • tab[]
    • C++
      • #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
           int n,x;
           cin>>n;
           vector<int>v[4];
           for(int i=0;i<n;i++)
           {
               cin>>x;
               v[x].push_back(i+1);
           }
        
           int t=min(v[1].size(),min(v[2].size(),v[3].size()));
           cout<<t<<endl;
        
           for(int i=0;i<t;i++)
        
           {
               cout<<v[1][i]<<" "<<v[2][i]<<" "<<v[3][i]<<endl;
           }
           return 0;
        }
3/Technology/post-list
Name

Codeforces,53,Problem Solve,90,Programming Tricks,1,URI,37,
ltr
item
DorHubs: Codeforces 490 - A problem solution
Codeforces 490 - A problem solution
DorHubs
https://dorhubs.blogspot.com/2019/07/codeforces-490-problem-solution.html
https://dorhubs.blogspot.com/
https://dorhubs.blogspot.com/
https://dorhubs.blogspot.com/2019/07/codeforces-490-problem-solution.html
true
9087637800571592252
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy