using System; using System.Diagnostics.CodeAnalysis; namespace Csharp { class Program { class Meeting : IComparable<Meeting> { public uint Start; public uint End; public Meeting(uint s, uint e) { Start = s; End = e; } public int CompareTo([AllowNull] Meeting other) { if (End.CompareTo(other.End) != 0) return End.CompareTo(other.End); return Start.CompareTo(other.Start); } } static int N; static Meeting[] Meetings = new Meeting[100000]; static void Main(string[] args) { N = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < N; i++) { var inputs = Console.ReadLine().Split(); Meetings[i] = new Meeting( Convert.ToUInt32(inputs[0]), Convert.ToUInt32(inputs[1])); } Array.Sort(Meetings, 0, N); int ans = 1; int cur = 0; for (int i = 1; i < N; i++) { if (Meetings[cur].End <= Meetings[i].Start) { ++ans; cur = i; } } Console.Write(ans); } } } |