Hello,
I am getting an NZEC error when submitting my solution to the Lowest Sums problem under the easy category for the practice problems and I cannot understand why. Using both Visual Studio and MonoDevelop and testing under the .NET and gcms (Mono) compilers for C#, the program runs correctly and works fine. However, using Mono, I get an error after the program is finished running - which does not occur when running the .NET debugger. The error I get is:
“Assertion at mono-threads-windows c:99 condition !mono_domain_get () not met”
The program runs correctly, and then that error message comes up. Below is my code:
using System;
namespace Lowest_Sums
{
class Program
{
static void Main(string[] args)
{
string s_cases = Console.ReadLine();
int cases = int.Parse(s_cases);
for (int k = 0; k < cases; k++)
{
string line1 = Console.ReadLine();
string[] ln_split = line1.Split(' ');
int chefs = int.Parse(ln_split[0]);
int queries = int.Parse(ln_split[2]);
int[] sums = new int[chefs * chefs];
string s_satis = Console.ReadLine();
string s_motiv = Console.ReadLine();
string[] c_satisfaction = s_satis.Split(' ');
string[] c_motivation = s_motiv.Split(' ');
int curr_sum = 0;
for (int i = 0; i < chefs; i++)
{
for (int l = 0; l < chefs; l++)
{
int value1 = int.Parse(c_satisfaction[i]);
int value2 = int.Parse(c_motivation[l]);
sums[curr_sum] = (value1 + value2);
curr_sum++;
}
}
int[] sums_sorted = MergeSort(sums);
for (int j = 0; j < queries; j++)
{
string s_n = Console.ReadLine();
int n = int.Parse(s_n);
Console.WriteLine(sums_sorted[n - 1]);
}
}
}
static int[] MergeSort(int[] array)
{
if (array.Length == 1)
return array;
int[] sorted = new int[array.Length];
int mid = (int)(array.Length / 2);
int[] left = new int[mid];
int[] right = new int[array.Length - mid];
for (int p = 0; p < mid; p++)
left[p] = array[p];
int counter = 0;
for (int p = mid; p < array.Length; p++)
{
right[counter] = array[p];
counter++;
}
left = MergeSort(left);
right = MergeSort(right);
int leftptr = 0, rightptr = 0;
for (int k = 0; k < left.Length + right.Length; k++)
{
if (leftptr == left.Length)
{
sorted[k] = right[rightptr];
rightptr++;
}
else if (rightptr == right.Length)
{
sorted[k] = left[leftptr];
leftptr++;
}
else if (left[leftptr] < right[rightptr])
{
sorted[k] = left[leftptr];
leftptr++;
}
else
{
sorted[k] = right[rightptr];
rightptr++;
}
}
return sorted;
}
}
}
I’m using MergeSort to sort the final array. Thanks in advance.