Submission #30442020


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks
{
    public class C
    {
        public static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, K) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<int>().ToArray();
            var B = Scanner.ScanEnumerable<int>().ToArray();
            var dp1 = new HashSet<int> { A[0], B[0] };
            for (var i = 1; i < N; i++)
            {
                var dp2 = new HashSet<int>();
                var (a, b) = (A[i], B[i]);
                foreach (var v in dp1)
                {
                    if (Math.Abs(v - a) <= K) dp2.Add(a);
                    if (Math.Abs(v - b) <= K) dp2.Add(b);
                }

                dp1 = dp2;
            }

            var answer = dp1.Count > 0;
            Console.WriteLine(answer ? "Yes" : "No");
        }

        public static long BinarySearch(long ng, long ok, Func<long, bool> func)
        {
            while (Math.Abs(ok - ng) > 1)
            {
                var m = (ok + ng) / 2;
                if (func(m)) ok = m;
                else ng = m;
            }
            return ok;
        }

        public static class Scanner
        {
            public static string ScanLine() => Console.ReadLine()?.Trim() ?? string.Empty;
            public static string[] Scan() => ScanLine().Split(' ');
            public static T Scan<T>() where T : IConvertible => Convert<T>(Scan()[0]);
            public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]));
            }
            public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]));
            }
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]));
            }
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]));
            }
            public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]), Convert<T6>(line[5]));
            }
            public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => Scan().Select(Convert<T>);
            private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
        }
    }
}

Submission Info

Submission Time
Task C - Choose Elements
User AconCavy
Language C# (.NET Core 3.1.201)
Score 300
Code Size 3794 Byte
Status AC
Exec Time 213 ms
Memory 80836 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 27
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 87 ms 32676 KiB
001.txt AC 80 ms 27936 KiB
002.txt AC 89 ms 32676 KiB
003.txt AC 75 ms 28308 KiB
004.txt AC 79 ms 27952 KiB
005.txt AC 74 ms 28068 KiB
006.txt AC 213 ms 80328 KiB
007.txt AC 189 ms 80008 KiB
008.txt AC 187 ms 76384 KiB
009.txt AC 152 ms 75648 KiB
010.txt AC 208 ms 80564 KiB
011.txt AC 194 ms 80360 KiB
012.txt AC 206 ms 80816 KiB
013.txt AC 190 ms 80224 KiB
014.txt AC 204 ms 80680 KiB
015.txt AC 202 ms 80836 KiB
016.txt AC 208 ms 80216 KiB
017.txt AC 194 ms 80572 KiB
018.txt AC 199 ms 78376 KiB
019.txt AC 149 ms 71704 KiB
020.txt AC 212 ms 80264 KiB
021.txt AC 180 ms 80356 KiB
022.txt AC 200 ms 80360 KiB
023.txt AC 185 ms 80812 KiB
example0.txt AC 100 ms 28068 KiB
example1.txt AC 79 ms 28084 KiB
example2.txt AC 90 ms 28200 KiB