Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <stdio.h>
#include <vector>
using namespace std;
vector<int> pro, math, pe;
int main() {
int n;
scanf("%d", &n);
int tmp;
for(int i = 1; i <= n; i++) {
scanf("%d", &tmp);
if(tmp == 1) pro.push_back(i);
else if(tmp == 2) math.push_back(i);
else pe.push_back(i);
}
int mn = min(pro.size(), min(math.size(), pe.size()));
printf("%d\n", mn);
for(int i = 0; i < mn; i++)
printf("%d %d %d\n", pro[i], math[i], pe[i]);
return 0;
}
Copy The Code &
Try With Live Editor
Input
7
1 3 1 3 2 1 2
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
3 5 2
6 7 4
Demonstration
Codeforces Solution-Team Olympiad-Solution in C, C++, Java, Python