Submission #1610930


Source Code Expand

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static InputStream is;
    static PrintWriter out;
    static String INPUT = "";

    void solve() {
        long n = ni(), a = ni(), b = ni(), c = ni(), d = ni();
        long m = Math.min(a, b);
        a -= m;
        b -= m;
        if (a > b) {
            long t = a;
            a = b;
            b = t;
        }
        n -= 1;
        long min = -1, max = n;
        while (max - min > 1) {
            long mid = (max + min) / 2;
            if (b <= mid * d - (n - mid) * c) {
                max = mid;
            } else {
                min = mid;
            }
        }
        long x = max * d - (n - max) * c;
        long y = max * c - (n - max) * d;
        out.println(y <= b && b <= x ? "YES" : "NO");
    }

    public static void main(String[] args) throws Exception {
        long S = System.currentTimeMillis();
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        new Main().solve();
        out.flush();
        long G = System.currentTimeMillis();
        tr(G - S + " ms");
    }

    private static boolean eof() {
        if (lenbuf == -1) return true;
        int lptr = ptrbuf;
        while (lptr < lenbuf)
            if (!isSpaceChar(inbuf[lptr++])) return false;

        try {
            is.mark(1000);
            while (true) {
                int b = is.read();
                if (b == -1) {
                    is.reset();
                    return true;
                } else if (!isSpaceChar(b)) {
                    is.reset();
                    return false;
                }
            }
        } catch (IOException e) {
            return true;
        }
    }

    private static byte[] inbuf = new byte[1024];
    static int lenbuf = 0, ptrbuf = 0;

    private static int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private static boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private static int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b))
            ;
        return b;
    }

    private static double nd() {
        return Double.parseDouble(ns());
    }

    private static char nc() {
        return (char) skip();
    }

    private static String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private static char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private static char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++)
            map[i] = ns(m);
        return map;
    }

    private static int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = ni();
        return a;
    }

    private static int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
            ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
            ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static void tr(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}

Submission Info

Submission Time
Task B - Moderate Differences
User hoshi524
Language Java8 (OpenJDK 1.8.0)
Score 400
Code Size 4959 Byte
Status AC
Exec Time 71 ms
Memory 24660 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 38
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt, sample4.txt
All sample1.txt, sample2.txt, sample3.txt, sample4.txt, a01.txt, a02.txt, a03.txt, a04.txt, b01.txt, b02.txt, b03.txt, b04.txt, c01.txt, c02.txt, c03.txt, c04.txt, d01.txt, d02.txt, d03.txt, d04.txt, d05.txt, d06.txt, d07.txt, d08.txt, d09.txt, d10.txt, d11.txt, d12.txt, d13.txt, d14.txt, d15.txt, d16.txt, d17.txt, d18.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt
Case Name Status Exec Time Memory
a01.txt AC 68 ms 21076 KB
a02.txt AC 68 ms 21204 KB
a03.txt AC 67 ms 19540 KB
a04.txt AC 68 ms 21204 KB
b01.txt AC 68 ms 18900 KB
b02.txt AC 67 ms 17620 KB
b03.txt AC 67 ms 21204 KB
b04.txt AC 68 ms 19284 KB
c01.txt AC 68 ms 20180 KB
c02.txt AC 67 ms 19540 KB
c03.txt AC 66 ms 19284 KB
c04.txt AC 68 ms 22868 KB
d01.txt AC 68 ms 17364 KB
d02.txt AC 68 ms 19412 KB
d03.txt AC 68 ms 20564 KB
d04.txt AC 70 ms 22740 KB
d05.txt AC 66 ms 21332 KB
d06.txt AC 67 ms 23252 KB
d07.txt AC 69 ms 21076 KB
d08.txt AC 70 ms 19156 KB
d09.txt AC 69 ms 21076 KB
d10.txt AC 71 ms 22996 KB
d11.txt AC 69 ms 19028 KB
d12.txt AC 68 ms 21076 KB
d13.txt AC 68 ms 21076 KB
d14.txt AC 68 ms 19284 KB
d15.txt AC 68 ms 21076 KB
d16.txt AC 68 ms 18004 KB
d17.txt AC 69 ms 19924 KB
d18.txt AC 68 ms 21076 KB
sample1.txt AC 67 ms 20180 KB
sample2.txt AC 69 ms 21204 KB
sample3.txt AC 68 ms 20564 KB
sample4.txt AC 68 ms 24660 KB