A. Red and Blue Beans | Edu Round 108 Div.2

LONGNEW·2021년 7월 12일
0

CP

목록 보기
35/155

https://codeforces.com/contest/1519/problem/A
시간 1초, 메모리 256MB

input :

  • t (1 ≤ t ≤ 1000)
  • r b d (1 ≤ r,b ≤ 109; 0 ≤ d ≤ 109)

output :

  • For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
    각 ㅌ스트케이스에서 콩들을 나눌 수 있으면 "YES"를 출력하고 그렇지 않은 경우에는 "NO"를 출력하시오.

조건 :

  • has at least one red bean (or the number of red beans ri≥1);
    has at least one blue bean (or the number of blue beans bi≥1);
    the number of red and blue beans should differ in no more than d (or |ri−bi|≤d)
    각 패킷에는 최소한 빨간 콩이 1개, 파란 콩이 1개 여야 하고 둘의 차이가 d보다 작아야 한다.

만약 d가 0이라면 r, b의 크기가 같아야 한다.

그렇지 않은 경ㅇ

r, b 둘 중 작은 값을 찾아서 작은거 1개를 넣을 때 나머지를 다 수용할 수 있는지 확인 해야 한다.

import sys

t = int(sys.stdin.readline())
for _ in range(t):
    r, b, d = map(int, sys.stdin.readline().split())

    small = min(r, b)
    big = max(r, b)

    if d == 0:
        print("YES" if r == b else "NO")
    else:
        print("YES" if small * (d + 1) >= big else "NO")

0개의 댓글