Submission #71330027


Source Code Expand

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);

        int T = sc.nextInt();
        while (T-- > 0) {
            int N = sc.nextInt();
            long H = sc.nextLong();

            long currentMin = H;
            long currentMax = H;
            long prevT = 0;
            boolean possible = true;

            for (int i = 0; i < N; i++) {
                long t = sc.nextLong();
                long l = sc.nextLong();
                long u = sc.nextLong();

                if (!possible) continue;

                long dt = t - prevT;
                long reachLow = currentMin - dt;
                long reachHigh = currentMax + dt;

                currentMin = Math.max(reachLow, l);
                currentMax = Math.min(reachHigh, u);

                if (currentMin > currentMax) {
                    possible = false;
                }

                prevT = t;
            }

            out.println(possible ? "Yes" : "No");
        }
        out.flush();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Submission Info

Submission Time
Task C - Flapping Takahashi
User addy
Language Java24 (OpenJDK 24.0.2)
Score 300
Code Size 1904 Byte
Status AC
Exec Time 234 ms
Memory 59552 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 29
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 44 ms 38404 KiB
01_small_00.txt AC 234 ms 58960 KiB
01_small_01.txt AC 221 ms 58600 KiB
01_small_02.txt AC 210 ms 59340 KiB
01_small_03.txt AC 202 ms 58792 KiB
01_small_04.txt AC 192 ms 59320 KiB
01_small_05.txt AC 199 ms 58964 KiB
01_small_06.txt AC 195 ms 58636 KiB
01_small_07.txt AC 195 ms 58504 KiB
02_random_00.txt AC 181 ms 58972 KiB
02_random_01.txt AC 190 ms 59088 KiB
02_random_02.txt AC 191 ms 59104 KiB
02_random_03.txt AC 181 ms 59100 KiB
02_random_04.txt AC 190 ms 58928 KiB
02_random_05.txt AC 190 ms 59540 KiB
02_random_06.txt AC 182 ms 58924 KiB
02_random_07.txt AC 184 ms 58652 KiB
02_random_08.txt AC 193 ms 59092 KiB
02_random_09.txt AC 160 ms 56632 KiB
02_random_10.txt AC 190 ms 59120 KiB
02_random_11.txt AC 190 ms 59240 KiB
02_random_12.txt AC 185 ms 59060 KiB
02_random_13.txt AC 191 ms 59552 KiB
02_random_14.txt AC 187 ms 58316 KiB
02_random_15.txt AC 191 ms 58696 KiB
02_random_16.txt AC 175 ms 59528 KiB
02_random_17.txt AC 188 ms 58764 KiB
02_random_18.txt AC 189 ms 58844 KiB
02_random_19.txt AC 190 ms 59004 KiB