I'm a new programmer, I was solving a problem at codeforces when I got this error.
http://codeforces.com/contest/342/problem/A
My algorithm works fine but I don't know why at the very end, I have an error message and a return value different from 0. It's shown in the picture below.
https://i.sstatic.net/sz9Jc.png
Thank you in advance !!
Here is my algorithm:
#include <iostream> #include <vector> using namespace std; void print(int a, int b, int c, int n) { for (int i=0;i<n;++i) cout<<a<<" "<<b<<" "<<c<<endl; } int main () { int n; cin>>n; vector<int> V(5); bool cont=true; for (int i=0;i<n;++i) { V[i]=0; } for (int i=0;i<n;++i) { int a; cin>>a; if (a==5 || a==7) cont=false; if (cont==true) { if (a==1) V[0]++; if (a==2) V[1]++; if (a==3) V[2]++; if (a==4) V[3]++; if (a==6) V[4]++; } } if (cont==false) { cout<<-1<<endl; }else { if (V[0]==V[1] && V[1]==V[3] && V[2]==0 && V[4]==0) { print(1,2,4,V[0]); }else if (V[0]==V[1] && V[1]==V[4] && V[2]==0 && V[3]==0) { print(1,2,6,V[0]); }else if (V[0]==V[2] && V[2]==V[4] && V[1]==0 && V[3]==0) { print(1,3,6,V[0]); }else if (V[0]==V[1] && V[1]==(V[4]+V[3]) && V[2]==0) { print(1,2,4,V[3]); print(1,2,6,V[4]); } else if (V[0]==V[4] && V[0]==(V[1]+V[2]) && V[3]==0) { print(1,2,6,V[1]); print(1,3,6,V[2]); } else if (V[0]==(V[1]+V[2]) && V[0]==(V[3]+V[4]) && V[3]==V[1]) { print(1,2,4,V[1]); print(1,3,6,V[2]); } else if (V[0]==(V[1]+V[2]) && V[0]==(V[4]+V[3]) && V[3]==(V[1]/2) && V[2]==(V[4]/2)){ print(1,2,4,V[3]); print(1,2,6,V[1]-V[3]); print(1,3,6,V[2]); } else { cout<<-1<<endl; } } cout<<"fin"<<endl; return 0; }