33972023-02-27 12:27:04BenedekÁruszállítás üres szakaszaicsharpAccepted 50/50280ms37340 KiB
using System;
using System.Linq;

namespace Áruszállításüreszakaszai
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = st[0];
            int m = st[1];

            int[] p = new int[2 * m + 1];
            int[] k = new int[2 * m + 1];
            p[p.Length - 1] = 1000000000;
            int pi = 0;

            for (int i = 0; i < m; i++)
            {
                st = Console.ReadLine().Split().Select(int.Parse).ToArray();

                p[pi] = st[0];
                k[pi] = 0;
                pi++;
                p[pi] = st[1];
                k[pi] = 1;
                pi++;


            }
            Array.Sort(p, k);
            int kezdo = 0;
            int vegzo = 0;
            int db = 0;

            for (int i = 0; i < p.Length; i++)
            {
                if (k[i] == 0)
                {
                    kezdo++;

                }
                else
                {
                    vegzo++;
                }
                if (i < p.Length - 1 && p[i] < p[i+1])
                {
                    if (kezdo == vegzo)
                    {
                        db++;
                    }
                }
                

            }
            if (p[0] != 1)
            {
                db++;
            }
            if (p[m * 2 - 1] == N)
            {
                db--;
            }

            Console.WriteLine(db);
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/035ms22448 KiB
2Accepted0/0280ms33540 KiB
3Accepted2/232ms22808 KiB
4Accepted2/232ms23112 KiB
5Accepted2/232ms23372 KiB
6Accepted2/232ms23528 KiB
7Accepted2/235ms23964 KiB
8Accepted2/234ms24288 KiB
9Accepted2/232ms24340 KiB
10Accepted2/235ms24536 KiB
11Accepted2/235ms24544 KiB
12Accepted2/234ms25128 KiB
13Accepted3/348ms28164 KiB
14Accepted3/354ms29256 KiB
15Accepted3/345ms27564 KiB
16Accepted3/3223ms35940 KiB
17Accepted3/3216ms36380 KiB
18Accepted3/3248ms36972 KiB
19Accepted3/354ms30660 KiB
20Accepted3/357ms31340 KiB
21Accepted3/3261ms36772 KiB
22Accepted3/3275ms37340 KiB