Problem:


Score : 300 points

Problem Statement

You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N.
Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.

Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions simultaneously:

Add 2 to a_i.

Add 1 to b_j.

Constraints

1 ≤ N ≤ 10 000

0 ≤ a_i,b_i ≤ 10^9 (1 ≤ i ≤ N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 .. a_N
b_1 b_2 .. b_N

Output

If we can repeat the operation zero or more times so that the sequences a and b become equal, print Yes; otherwise, print No.

Sample Input 1

3
1 2 3
5 2 2

Sample Output 1

Yes

For example, we can perform three operations as follows to do our job:

First operation: i=1 and j=2. Now we have a = \{3,2,3\}, b = \{5,3,2\}.

Second operation: i=1 and j=2. Now we have a = \{5,2,3\}, b = \{5,4,2\}.

Third operation: i=2 and j=3. Now we have a = \{5,4,3\}, b = \{5,4,3\}.

Sample Input 2

5
3 1 4 1 5
2 7 1 8 2

Sample Output 2

No

Sample Input 3

5
2 7 1 8 2
3 1 4 1 5

Sample Output 3

No



Sample input:
3
1 2 3
5 2 2


Sample output:
Yes

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.q = l
        heapq.heapify(self.q)
        return

    def push(self, n):
        heapq.heappush(self.q, n)
        return

    def pop(self):
        return heapq.heappop(self.q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    n = Scanner.int()
    A = Scanner.map_int()
    B = Scanner.map_int()
    cnt = 0
    for i in range(n):
        if A[i] < B[i]:
            cnt += (B[i] - A[i]) // 2
        else:
            cnt -= (A[i] - B[i])
    print('NYoe s'[cnt >= 0::2])
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
total = sum(B) - sum(A)
cnt1, cnt2 = 0,0

for i in range(n):
    if A[i] > B[i]:
        cnt1 += A[i] - B[i]
    elif A[i] < B[i]:
        cnt2 += math.ceil((B[i]-A[i])/2)

if max(cnt1, cnt2) <= total:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

import math

count_1up = 0
count_2up = 0

for a, b in zip(A, B):
    if a - b >= 0:
        count_1up += a - b
    else:
        count_2up += math.ceil((b - a) / 2)

diff = sum(B) - sum(A)

# print(diff, count_1up, count_2up)
if diff < 0:
    print("No")
elif diff < count_1up or diff < count_2up:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
def ceil(a, b):
    return (a + b - 1) // b


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = sum(b) - sum(a)
for _a, _b in zip(a, b):
    if _a < _b:
        n -= ceil(_b - _a, 2)
if n >= 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def ceil(a, b):
    return (a + b - 1) // b


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = sum(b) - sum(a)
cnt = 0
for _a, _b in zip(a, b):
    if _a < _b:
        cnt += ceil(_b - _a, 2)
if cnt <= n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = sum(b) - sum(a)
cnt = 0
for i in range(n):
  if b[i] < a[i]:
    cnt += a[i] - b[i]
  elif (b[i] + a[i]) % 2 == 1:
    cnt += 1
if cnt <= k:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d=0,0
for i in range(n):
    if a[i]>b[i]:
        c+=a[i]-b[i]
    else:
        d+=(b[i]-a[i])//2
if d>=c:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
b = 0
for i in range(N):
    if A[i]>B[i]:b+=(A[i]-B[i])
for i in range(N):
    if A[i]<B[i]:
        c = (B[i]-A[i])//2
        if c<=b:b-=c
        elif c>b:b=0
print("No" if b else "Yes")

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
T=sum(B)-sum(A)
ca=0
cb=0
for a,b in zip(A,B):
    if a>b:
        cb+=a-b
    elif b>a:
        ca+=(b-a+1)//2
        cb+=(b-a)&1
print("YNeos"[ca<cb::2])

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
ab = [[0,0] for i in range(n)]
lsta = list(map(int,input().split()))
lstb = list(map(int,input().split()))
for i in range(n):
    ab[i][0] = lsta[i]
    ab[i][1] = lstb[i]

bstock = 0

move = sum(lstb) - sum(lsta)

if move == 0:
    if lsta == lstb:
        print("Yes")
    else:
        print("No")
    exit()

ab.sort()
i = 0
while i < n-1:
    if ab[i][0] > ab[i][1]: #bstockを使う
        if ab[i][0] > ab[i][1]+bstock:
            print("No")
            exit()
        else:
            bstock -= ab[i][0]-ab[i][1]
    elif ab[i][0]%2 == ab[i][1]%2:
        bstock += (ab[i][1]-ab[i][0])//2
        move -= (ab[i][1]-ab[i][0])//2
    else:
        move -= (ab[i][1]-ab[i][0])//2 + 1
        bstock += (ab[i][1]-ab[i][0])//2
    if move < 0 or bstock < 0:
        print("No")
        exit()    
    i+= 1

if ab[-1][0]+(move*2)==ab[-1][1]+move+bstock:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n = ni()
a = na()
b = na()

p = 0
q = 0

for i in range(n):
    if a[i] < b[i]:
        m = b[i] - a[i]
        if m % 2 == 1:
            m -= 1
        p += m
    else:
        q += a[i] - b[i]

p //= 2

if p >= q:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=LI()
  l2=LI()

  sm1=sum(l1)
  sm2=sum(l2)

  nm=sm2-sm1
  if nm<0:
    return 'No'

  nm1=0
  for i in range(n):
    a=l1[i]
    b=l2[i]

    if a<b:
      _a=(b-a+1)//2
      l1[i]+=_a*2
      nm1+=_a

  nm2=0
  for i in range(n):
    a=l1[i]
    b=l2[i]

    if a>b:
      _a=a-b
      nm2+=_a

  # print(nm,nm2)
  if nm<max(nm1,nm2):
    return 'No'

  return 'Yes'

# main()
print(main())

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sousa=sum(b)-sum(a)
cnt=0
for i in range(n):
	if b[i]>a[i]:
		cnt+=(b[i]-a[i]+1)//2
if sousa>=cnt:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

excess = 0
for i in range(N):
    dif = a[i]-b[i]
    if dif < 0:
        excess += abs(dif)//2
    elif 0 < dif:
        excess -= dif

if 0<=excess:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

sub1 = 0
sub2 = 0

for i in range(n):
    if a[i] > b[i]:
        sub1 += a[i] - b[i]
    else:
        sub2 += (b[i] - a[i]) // 2

if sub1 <= sub2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for a, b in zip(A, B):
    if a > b:
        cnt -= a - b
    if a < b:
        cnt += (b - a) // 2

if cnt < 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_A = sum(A)
sum_B = sum(B)
cnt1 = sum_B - sum_A
cnt2 = 0
for a, b in zip(A, B):
    # if a > b:
    #     cnt2 += a - b
    if a < b:
        cnt2 += math.ceil((b - a) / 2)

if cnt1 >= cnt2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]", b: "List[int]"):
    A_sum = sum(a)
    B_sum = sum(b)
    if A_sum > B_sum:
        print(NO)
        return
    
    dif = [a[i]-b[i] for i in range(N)]
    one = 0
    two = 0
    for i in range(N):
        if dif[i] > 0:
            one += dif[i]
        if dif[i] < 0:
            two += -(dif[i]//2)
    
    if max(one,two) > B_sum-A_sum:
        print(NO)
    else:
        print(YES)
    # minimum_operations = []

    # for i in range(N):
    #     if dif[i] >= 0:
    #         minimum_operations.append(dif[i])
    #     else:
    #         minimum_operations.append(-(dif[i]//2))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnta, cntb = 0, 0
for i in range(N):
  a, b = A[i], B[i]
  if a > b :
    cntb += a-b
    continue
  if (b-a)%2 > 0:
    cntb += 1
    b += 1
    
  cnta += (b-a) // 2
  
#print(cnta, cntb)
print('Yes' if cnta >= cntb else 'No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

suma = sum(a)
sumb = sum(b)
sousa = sumb-suma

import math
plus1=0
plus2=0
for i in range(n):
    if a[i] < b[i]:
        plus2+=math.ceil((b[i]-a[i])/2)
    elif a[i] > b[i]:
        plus1+=a[i]-b[i]

if plus1<=sousa and plus2<=sousa:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if sum(a) > sum(b):
    print('No')
elif a == b:
    print('Yes')
elif sum(a) == sum(b):
    print('No')
else:
    count = 0
    diff = 0
    for ai,bi in zip(a,b):
        if ai == bi:
            continue
        elif ai < bi:
            diff += (bi-ai)//2
            continue
        else:
            count += (ai-bi)
    if diff >= count:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    plus = 0
    minus = 0
    for a, b in zip(A, B):
        if b - a > 0:
            plus += (b - a)//2
        else:
            minus += a - b
    if plus >= minus:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = y = 0
for i in range(n):
    x += b[i]-a[i]
    if a[i]<b[i]: y+=(b[i]-a[i]+1)//2
print("YNeos"[y>x::2])

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
A = sum(a);B = sum(b)
count_1 = 0
count_2 = 0
total = B-A
for i,j in zip(a,b):
    if i < j:
        count_1 += (j-i+1)//2
    else:
        count_2 += i-j
count = max(count_1,count_2)
if count <= total:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

n = 0
for j in range(N):
    if B[j] < A[j]:
        n += A[j] - B[j]
        B[j] = A[j]
    elif (B[j] - A[j]) % 2 == 1:
        n += 1
        B[j] += 1

s = sum([b - a for a, b in zip(A, B)])
print("Yes" if s % 2 == 0 and s >= 2 * n else "No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if sum(a)>sum(b):
  print("No")
else:
  ca = 0
  cb = 0
  for i in range(n):
    if a[i]>b[i]:
      cb += a[i]-b[i]
    else:
      ca += (b[i]-a[i]+1)//2
      cb += (b[i]-a[i])%2
  x = sum(b)-sum(a)
  if x >= ca and x >= cb and (x-ca)*2 == x-cb:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

cnta = 0
cntb = 0
k = sum(b)-sum(a)
for i in range(n):
    d = abs(a[i]-b[i])
    if a[i] > b[i]:
        cntb += d
    else:
        cnta += (d+1)//2
        cntb += d%2

if k < 0 or cntb > cnta or k != 2*cnta - cntb:
    ans = "No"
else:
    ans = "Yes"
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_cnt = 0
b_cnt = 0
for i in range(n):
    if a[i] > b[i]:
        b_cnt += (a[i] - b[i])
    elif a[i] < b[i]:
        k  = (b[i] - a[i])
        if k % 2 == 0:
            a_cnt += k//2
        else:
            b_cnt += 1
            a_cnt += (k+1)//2
if a_cnt >= b_cnt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import heapq

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

B_pool = 0
deck = []
for i in range(N):
	heapq.heappush(deck, A[i]-B[i])

while deck:
	diff = heapq.heappop(deck)
	if diff <= 0:
		B_pool += (-diff) // 2
	else:
		B_pool -= diff

if B_pool >= 0:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
for i, j in zip(a, b):
    if i < j:
        cnt += (j - i) // 2 + (j - i) % 2
sa = sum(b) - sum(a)
if cnt <= sa:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

k = sum(bl) - sum(al)

def ceil(a, b):
   return a // b + (a % b > 0)

up = 0
down = 0
for a, b in zip(al,bl):
    if b - a > 0:
        up += ceil(b-a, 2)
        down = (b-a) % 2
    else:
        down = (a-b)

if k >= up and k >= down:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

use_clipboard=False
bbn=1000000007
	
#+++++

		
def main():
	n = int(input())
	bl = list(map(int, input().split()))
	cl = list(map(int, input().split()))
	
	dd = sum([max(c-b,0) for b,c in zip(bl,cl)])
	pp = sum([max(b-c,0) for b,c in zip(bl, cl)])
	
	ss=sum([(c-b) % 2 for b,c in zip(bl,cl) if c >= b])
	pa(('dd',dd,'pp',pp))
	if (dd - ss)< pp*2:
		return 'No'
	
	return 'Yes'
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

for i in range(n):
    if a[i] < b[i]:
        cnt += (b[i] - a[i]) // 2
    else:
        cnt -= (a[i] - b[i])

print("Yes" if cnt >= 0 else "No")

Submission status: Accepted

Solution code:
# http://logfiles.hatenablog.com/entry/2018/06/30/215140

def main():
    n = int(input())
    *a, = map(int, input().split())
    *b, = map(int, input().split())

    cnt = sum(b) - sum(a)

    if cnt < 0:
        print('No')
        return

    elif cnt == 0:
        print('Yes' if a == b else 'No')
        return

    na = 0
    for i in range(n):
        if a[i] < b[i]:
            t = (b[i] - a[i] + 1) // 2
            a[i] += t * 2
            na += t

    nb = 0
    for i in range(n):
        if a[i] > b[i]:
            t = a[i] - b[i]
            b[i] += t
            nb += t

    print('Yes' if na >= nb else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(A) > sum(B):
    print("No")
else:
    cnt = 0
    b = 0
    for i in range(N):
        if A[i] < B[i]:
            cnt += (B[i] - A[i]) // 2
        elif A[i] > B[i]:
            b -= A[i] - B[i]

    if b + cnt >= 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

max_count = sum(B) - sum(A)

count1, count2 = 0, 0

for i in range(N):
  if A[i] > B[i]:
    count1 += A[i] - B[i]
  else:
    count2 += (B[i] - A[i]) // 2
    if (B[i] - A[i]) % 2 == 1:
      count2 += 1
      
if count1 <= max_count:
  if count2 <= max_count:
    print("Yes")
    quit()
print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

tmp = sum(b) - sum(a)
numa, numb = 0, 0
for i in range(N):
    if a[i] > b[i]:
        numb += a[i] - b[i]
    elif a[i] < b[i]:
        numa += (b[i] - a[i] + 1) // 2

if numa <= tmp and numb <= tmp:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count_a = 0
count_b = 0
for i in range(n):
    count_a += max(0,(b[i]-a[i]+1)//2)
    count_b += max(0,a[i]-b[i])
if sum(b)>=sum(a) and sum(b)-sum(a)>=max(count_a,count_b):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = sum(b) - sum(a)

numa, numb = 0, 0
for i in range(n):
    if a[i] > b[i]:
        numb += a[i] - b[i]
    elif a[i] < b[i]:
        numa += (b[i] - a[i] + 1) // 2

# if numa <= dif and numb <= dif:
if numa <= dif:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = sum(b) - sum(a)

numa, numb = 0, 0
for i in range(n):
    if a[i] > b[i]:
        numb += a[i] - b[i]
    elif a[i] < b[i]:
        numa += (b[i] - a[i] + 1) // 2

if numa <= dif and numb <= dif:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

sabun=[B[i]-A[i] for i in range(N)]
sabun.sort()
num=0
for n in sabun:
    if n<0:
        num+=n
    else:
        num+=n//2
print("Yes" if num>=0 else "No")

Submission status: Accepted

Solution code:
import sys


N, *AB = map(int, open(0).read().split())
A = AB[:N]
B = AB[N:]

# 手前から数を揃えて余りを蓄積させていく
# 最後に余りをやりくりできれば Yes さもなくば No 
res_a = 0
res_b = 0
for i, (a, b) in enumerate(zip(A, B)):
  if i < N - 1:
    if a == b:
      continue
    
    # b の方が大きい場合、偶奇を合わせて res_b を増やす
    elif a < b:
      # 偶奇を合わせる
      if (b - a) % 2:
        b += 1
        if res_b:
          res_b -= 1
        else:
          a += 2
          
      # res_a が余っていれば補填する
      if b - a <= res_a:
        res_a -= b - a
      # res_a で補填できなければ res_b を増やす
      else:
        a += res_a
        res_a = 0
        res_b += (b - a) // 2
      
    else:
      # bの方が小さい場合、余っている数で補填する
      # 補填できれば、continue
      if a - b <= res_b:
        res_b -= a - b
      # 補填できなければ、偶奇を合わせて res_a を増やす
      else:
        b += res_b
        res_b = 0
        
        # 偶奇合わせ
        if (a - b) % 2:
          res_a += 2
          b += 1
        
        res_a += 2 * (a - b)
        
  
  else:
    a += res_a
    b += res_b
      
    if a > b:
      print("No")
      sys.exit()
    else:
      print("Yes")
      sys.exit()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
A = [int(v) for v in input().split()]
B = [int(v) for v in input().split()]
m = []

ca = 0
cb = 0
for i in range(N):
    a, b = A[i], B[i]
    if a > b:
        ca += a - b
    elif a < b:
        cb += ceil((b - a) / 2)

t = sum(B) - sum(A)
if ca <= t and cb <= t:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
limit = sum(B) - sum(A)
cnt_A = 0
cnt_B = 0
for i in range(N):
  if A[i] > B[i]:
    cnt_B += A[i] - B[i]
  elif A[i] < B[i]:
    cnt_A += math.ceil((B[i] - A[i]) / 2)
if cnt_A <= limit and cnt_B <= limit:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
d1 = 0
d2 = 0
for i in range(N):
    if A[i]>B[i]:
        d1 += (A[i]-B[i])
    else:
        d2 += (B[i]-A[i])//2
if d2>=d1:
    flag = 0
else:
    flag = 1
if flag==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
limit = sum(B) - sum(A)
cnt_A = 0
cnt_B = 0
for i in range(N):
  if A[i] > B[i]:
    cnt_B += A[i] - B[i]
  elif A[i] < B[i]:
    cnt_A += math.ceil((B[i] - A[i]) / 2)
if cnt_A <= limit and cnt_B <= limit:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
# 2行として上にa下にbを並べた時にai<biなら確実に同じ数にできる(同じインデックス同士だと1ずつ狭まるので)
# ai>biのときはai-bi回加算しなくてはならない 加算できる数はai<biの全てのiの(bi-ai)/2回分
n = int(input())
a, b = list(map(int, input().split())), list(map(int, input().split()))

pool = 0
use = 0
for i in range(n):
    if a[i] < b[i]:
        pool += (b[i] - a[i]) // 2
    elif b[i] < a[i]:
        use += a[i] - b[i]

print("Yes" if pool >= use else "No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
dif_pos, dif_neg = 0, 0
for a, b in zip(A,B):
  if a<b:dif_neg +=(b-a)//2
  elif b<a:dif_pos +=a-b
print('Yes' if dif_neg>=dif_pos else 'No')

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=b=0
for i in range(N):
    if A[i]>B[i]:
        a+=A[i]-B[i]
    else:
        b+=(B[i]-A[i])//2
if a>b:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
limit = sum(B) - sum(A)

if limit < 0:
    print("No")
else:
    need = 0
    for a, b in zip(A, B):
        if b < a:
            need += a-b
    can = 0
    for a, b in zip(A, B):
        if a < b:
            can += (b-a)//2
    if need > can:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sum(b) - sum(a)
if c < 0:
  print("No")
  exit(0)
x = a + []
#print(c)
for i in range(N):
  if x[i] < b[i]:
    c += -(b[i] - x[i]) // 2
    x[i] = b[i]

if c < 0:
  print("No")
else: print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
A=[int(a) for a in input().split()]
B=[int(b) for b in input().split()]
x,y=0,0
for i in range(N):
  d=B[i]-A[i]
  if d>0:
    x+=d//2+d%2
    y+=d%2
  else:
    y-=d
print(['No','Yes'][x>=y])

Submission status: Accepted

Solution code:
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
# 全部正ならok
# 負に1足して正から2を引く
diff_ls = [b - a for a, b in zip(a_ls, b_ls)]
diff_ls.sort()
diff_ls = [i if i <= 0 else i // 2 for i in diff_ls]
if sum(diff_ls) >= 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sorted([a[i]-b[i] for i in range(N)])
k=-sum(c)
# print(c,k)
cp=[ci for ci in c if ci>0]
cn=[ci for ci in c if ci<0]

# 必要な「1増やす回数」
p=sum(cp)+sum([cni%2 for cni in cn])
# 必要な「2減らす回数」
n=sum([(-cni+1)//2 for cni in cn])

f=k>=0 and p<=k and n<=k

print('Yes' if f else 'No')

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]

x = sum(B) - sum(A)
if x >= 0 and sum([max(a-b, a+b&1) for a, b in zip(A, B)]) <= x:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    sum_A = np.sum(A)
    sum_B = np.sum(B)
    diff_AB = A - B

    if sum_A > sum_B:
        ans = 'No'
    else:
        cnt_1 = 0
        cnt_2 = 0
        for d in diff_AB:
            if d > 0:
                cnt_1 += d
            else:
                cnt_2 += (-d + 1) // 2

        if max(cnt_1, cnt_2) <= sum_B - sum_A:
            ans = 'Yes'
        else:
            ans = 'No'

    print(ans)


main()

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

d=[0]*N
p=0
m=0
c=0
for i in range(N):
    d[i]=a[i]-b[i]
    if(d[i]>0):
        p+=d[i]
    else:
        m+=d[i]
        if(abs(d[i])%2==1):
            c+=1
m+=c

if(abs(m)>=(abs(p)*2)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

tmp = 0

for i in range(N):
    if A[i]==B[i]:
        continue
    elif A[i]<B[i]:
        tmp += (B[i]-A[i])//2
    else:
        tmp += B[i]-A[i]
if tmp>=0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a,b = 0,0
for i in range(N):
    if A[i]>B[i]:
        b += A[i]-B[i]
    else:
        a += (B[i]-A[i])//2+(B[i]-A[i])%2
if (sum(B)-sum(A))>=max(a,b):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ca = 0
cb = 0
for i, j in zip(a, b):
    if i < j:
        ca += ceil((j-i)/2)
    else:
        cb += i-j
n = sum(b)-sum(a)
print("Yes" if n >= cb and n >= ca else "No")

Submission status: Accepted

Solution code:
def examB():
    N = I()
    A = LI(); B = LI()
    dif = sum(B) -sum(A)
    cur = 0
    for i in range(N):
        if A[i]>=B[i]:
            cur += A[i]-B[i]
        elif (A[i]-B[i])%2==1:
            cur +=1
    if dif>=cur:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

pm = 0
for i in range(N) :
    if a[i] >= b[i] :
        pm += 2 * (a[i] - b[i])
    else :
        if a[i] % 2 != b[i] % 2 :
            pm += 1
        pm -= b[i] - a[i]
        
if pm > 0 :
    print('No')
else :
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

pm = 0
for i in range(N) :
    if a[i] >= b[i] :
        pm += 2 * (a[i] - b[i])
    else :
        if a[i] % 2 != b[i] % 2 :
            pm += 1
        pm -= b[i] - a[i]
        
if pm > 0 :
    print('No')
else :
    print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

# 解説AC
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    n = 0
    for a, b in zip(A, B):
        if a > b:
            n += a - b
    for a, b in zip(A, B):
        if a < b:
            n -= (b - a)//2
    if n <= 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    nega = 0
    posi = 0
    A = (int(i) for i in input().split())
    B = (int(i) for i in input().split())
    for a, b in zip(A, B):
        diff = a-b
        if diff < 0:
            nega += abs(diff)//2
        else:
            posi += diff
    if posi <= nega:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()