47042023-03-31 09:44:15csicsilla70Leghosszabb béke (75 pont)csharpAccepted 75/75173ms32836 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace leghosszabb_béke
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sor = Console.ReadLine().Split();
            int napok = int.Parse(sor[0]);
            int[] x = new int[napok + 1];
            int n = int.Parse(sor[1]);           
            for (int i = 0; i < n; i++)
            {
                sor = Console.ReadLine().Split();
                x[int.Parse(sor[0])]++;
                x[int.Parse(sor[1])]--;
            }
            int szamlalo = 0;
            int k = 0, v = 0, mh = 0, mi = 0;
            for (int i = 1; i <= napok; i++)
            {
                szamlalo += x[i];
                if (szamlalo > 0) 
                    k = i + 1;
                else 
                { 
                    v = i;
                    if (v - k > mh) 
                    {                  
                        mh = v - k; 
                        mi = k;
                    }
                }
            }
            if (mh == 0) Console.WriteLine(-1);
            else Console.WriteLine(mh + " " + (mi + 1));
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/028ms20548 KiB
2Accepted0/0173ms29408 KiB
3Accepted3/327ms21428 KiB
4Accepted3/327ms21180 KiB
5Accepted3/327ms21312 KiB
6Accepted3/328ms21980 KiB
7Accepted3/328ms22464 KiB
8Accepted4/427ms22596 KiB
9Accepted4/427ms22640 KiB
10Accepted4/428ms22796 KiB
11Accepted4/437ms24936 KiB
12Accepted4/441ms25824 KiB
13Accepted4/435ms24840 KiB
14Accepted4/437ms25248 KiB
15Accepted4/441ms26072 KiB
16Accepted4/441ms26060 KiB
17Accepted4/439ms26080 KiB
18Accepted4/441ms26344 KiB
19Accepted4/4160ms32020 KiB
20Accepted4/4172ms32104 KiB
21Accepted4/4158ms32756 KiB
22Accepted4/4170ms32836 KiB