Logo
(追記) (追記ここまで)

34499번 - Balls and Bins 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB666100.000%

문제

Busy Beaver has $N$ bins and a large amount of balls. The $i$-th bin can hold up to $s_i$ balls and currently contains $a_i$ balls. In a move, he first chooses a bin $i$ that is currently full (i.e., $a_i = s_i$). Then, for each ball in the chosen bin, he chooses to either discard it or move it to a different bin with enough space. (Within the same move, it is allowed to move different balls to different bins.)

Using only these moves, Busy Beaver is trying to remove all of the balls from all of the bins. Determine whether or not it is possible to do so.

입력

Each test contains multiple test cases. The first line of input contains a single integer $T$ $(1\le T\le 10^5),ドル the number of test cases. The description of each test case follows.

The first line of each test case contains a single positive integer $N$ $(1\le N\le 5\cdot 10^5)$.

The second line contains $N$ integers $a_1,a_2,\dots, a_N$ $(1\le a_i\le 10^9)$ --- the number of balls currently in each bin.

The third line contains $N$ integers $s_1,s_2,\dots, s_N$ $(1\le s_i\le 10^9,a_i\le s_i)$ --- the number of balls each bin can hold.

It is guaranteed that the sum of $N$ across all test cases does not exceed 5ドル\cdot 10^5$.

출력

For each test case, output "YES" (without quotes) if all bins may be emptied, and "NO" (without quotes) otherwise.

제한

예제 입력 1

2
3
2 1 5
2 3 8
3
2 3 5
2 5 11

예제 출력 1

YES
NO

노트

In the first test case, Busy Beaver can move all the balls in the first bin to the second bin. Then he will have exactly 1ドル + 2 = 3$ balls in the second bin, making the second bin full.

Then he can move all the balls from the second bin to the third bin. Then he will have exactly 5ドル + 3 = 8$ balls in the third bin, making the third bin full.

Finally, he can throw all the balls in the third bin away.

In the second test case, it can be shown that it is impossible to discard all the balls.

출처

University > MIT > M(IT)^2 > M(IT)^2 Spring 2025 Invitational > Qualification Round 2 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /