I can't find mistake in mine solution to SnAckDown Chef and voting best friend solution.

here is my code

#include<iostream>
 
 
 
using namespace std;
 
 
 
int main()
{
	int T = 0;
 
	int N = 0;
	int sum = 0;
	int tmp = 0;
	bool flag = false;
	int arr[100];
	int arr1[100];
	cin >> T;
 
	for (int i = 0; i < T; i++)
	{ 
		flag = false;
		sum = 0;
 
		cin >> N;
		for (int j = 0; j < N; j++)
		{
			cin >> arr[j];
			//sum += tmp;
 
			//if (sum>N || tmp >= N)
			//{
			//	flag = true;
			//}
		}
 
		for (int a = 0; a < N; a++)
		{
			sum += arr[a];
 
			if (arr[a] >= N)
			{
				flag = true;
				break;
			}
 
			
			if (sum > N)
			{
				flag = true;
				break;
			}
 
		}
 
		if (sum < N)
			flag = true;
		if (flag)
		{
			cout << -1 << "\n";
		}
 
		else
		{
			int count1 = 0;
			for (int a = 0; a < N; a++)
			{
				
				for (int b = 0; b < N; b++)
				{
					if (b != a)
					{
						if (arr[b]>0)
						{
							arr[b]--;
							cout << b + 1<<"\t";
						}
					}
				}
 
 
				/*
				if (arr[a] != 0 && a!=N-1)
				{
					cout << a + 2<<" ";
				}
				else if (arr[a] != 0 && a == N - 1)
				{
					cout << 1;
				}*/
			}
			cout << "\n";
 
		}
	
	}
 
 
 
	return 0;
}

Your solution gives wrong answer for the test case :
1
5
0 0 2 1 2

Your code gives output : 3 4 5 3 5

Clearly, this is wrong since the 5th chef cannot vote himself.

Your code will fail with the below test case:
1
7
2 1 1 0 0 0 3