46922023-03-31 09:20:58TortelliniJrLeghosszabb béke (75 pont)csharpRuntime error 0/75190ms34588 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 = 1;
            int currentpeace = 0;
            int longestbegin = 0;
            for (int i = 1; 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 + " " + (longestbegin));
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Runtime error0/034ms21180 KiB
2Runtime error0/0190ms31652 KiB
3Runtime error0/332ms22356 KiB
4Runtime error0/332ms22524 KiB
5Runtime error0/332ms23180 KiB
6Runtime error0/334ms22944 KiB
7Runtime error0/332ms23064 KiB
8Runtime error0/432ms23488 KiB
9Runtime error0/432ms23508 KiB
10Runtime error0/432ms23824 KiB
11Runtime error0/443ms26644 KiB
12Runtime error0/446ms27900 KiB
13Runtime error0/441ms26580 KiB
14Runtime error0/445ms26976 KiB
15Runtime error0/446ms28196 KiB
16Runtime error0/432ms24600 KiB
17Runtime error0/432ms24488 KiB
18Runtime error0/432ms24908 KiB
19Runtime error0/4186ms34588 KiB
20Runtime error0/432ms25372 KiB
21Runtime error0/432ms26008 KiB
22Runtime error0/432ms26296 KiB