testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

Questions about programming?Chat with your personal AI assistant