Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Spoj task Bonus: ARRAYSUB – subarraysZadanie runtime error (NZEC) {c#}

Good morning I ran into a problem because look at the Bonus task: ARRAYSUB – subarrays task
it gives me a runtime error (NZEC) although ideone is not showing any error https://ideone.com/1eiciI Thank you

using System;
using System.Linq;
 
namespace ConsoleApp17
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int n = Convert.ToInt32((Console.ReadLine()));
 
            int k;
 
            int val = 0;
 
            int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            k = Convert.ToInt32((Console.ReadLine()));
 
            for (int i = 0; i < n - k + 1; i++)
            {
                val = arr[i];
                for (int j = i; j < i + k; j++)
                {
                    if (val < arr[j])
                    {
                        val = arr[j];
                    }
                }
 
                Console.Write(val + " ");
            }
        }
    }

I try to solve task and get accpeted

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That might help u
this type of error – when the program throws an exception. In this task, probably incorrectly loaded input or exceeding the range.

I propose:

 int[] arr = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading