46912023-03-31 09:07:12TortelliniJrLeghosszabb béke (75 pont)csharpWrong answer 42/75192ms34244 KiB
using System;
using System.Linq;
namespace LeghosszabbBeke
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] napok = new int[inp[0]];
            int[] temp = new int[2];
            for (int i = 0; i < inp[1]; i++)
            {
                temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                napok[temp[0]]++;
                napok[temp[1]]--;
            }
            int counter = 0;
            int longestpeace = 0;
            int currentpeace = 0;
            int longestbegin = 0;
            for (int i = 0; i < inp[0]; i++)
            {
                if (napok[i] > 0)
                {
                    counter += napok[i];
                }
                if (counter == 0)
                {
                    currentpeace++;
                }
                else
                {
                    if (currentpeace > longestpeace)
                    {
                        longestpeace = currentpeace;
                        longestbegin = i - currentpeace;
                    }
                    currentpeace = 0;
                }
                if (napok[i] < 0)
                {
                    counter += napok[i];
                }
            }
            if (currentpeace > longestpeace)
            {
                longestpeace = currentpeace;
                longestbegin = inp[0] + 1 - currentpeace;
            }
            if (longestpeace == 0)
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine(longestpeace + 1 + " " + (longestbegin - 1));
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base42/75
1Wrong answer0/032ms22256 KiB
2Accepted0/0192ms30812 KiB
3Runtime error0/332ms22160 KiB
4Wrong answer0/332ms23036 KiB
5Accepted3/330ms23564 KiB
6Wrong answer0/330ms23656 KiB
7Accepted3/329ms23588 KiB
8Accepted4/430ms23968 KiB
9Accepted4/430ms24372 KiB
10Accepted4/430ms24752 KiB
11Accepted4/441ms27636 KiB
12Accepted4/443ms28728 KiB
13Accepted4/439ms27444 KiB
14Accepted4/441ms28204 KiB
15Accepted4/445ms29224 KiB
16Runtime error0/432ms24684 KiB
17Runtime error0/432ms25332 KiB
18Runtime error0/434ms25456 KiB
19Accepted4/4181ms34244 KiB
20Runtime error0/432ms25860 KiB
21Runtime error0/432ms25844 KiB
22Runtime error0/432ms26368 KiB