46972023-03-31 09:28:55TortelliniJrLeghosszabb béke (75 pont)csharpAccepted 75/75186ms34248 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] + 1];
            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 (longestbegin == 0)
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine(longestpeace + " " + (longestbegin));
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/030ms21916 KiB
2Accepted0/0186ms30728 KiB
3Accepted3/332ms22580 KiB
4Accepted3/330ms22900 KiB
5Accepted3/330ms23564 KiB
6Accepted3/330ms23460 KiB
7Accepted3/329ms23704 KiB
8Accepted4/429ms23772 KiB
9Accepted4/430ms24072 KiB
10Accepted4/430ms24364 KiB
11Accepted4/439ms27128 KiB
12Accepted4/443ms28040 KiB
13Accepted4/441ms27256 KiB
14Accepted4/441ms27620 KiB
15Accepted4/446ms28996 KiB
16Accepted4/443ms29084 KiB
17Accepted4/443ms29596 KiB
18Accepted4/448ms30312 KiB
19Accepted4/4175ms34176 KiB
20Accepted4/4175ms34200 KiB
21Accepted4/4182ms34096 KiB
22Accepted4/4184ms34248 KiB