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:
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  a=LI()
  b=LI()

  sm1=sum(a)
  sm2=sum(b)

  cnt=sm2-sm1
  need=0
  for i in range(n):
    need+=max(0,(b[i]-a[i]+1)//2)

  if cnt<need:
    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(" ")))
a_cnt, b_cnt = 0, 0

for i in range(N):
    # aiをbiに近づける
    if a[i] < b[i]:
        num = (b[i] - a[i] + 1) // 2
        a_cnt += num
        a[i] += 2 * num

for i in range(N):
    # biをaiに近づける
    if b[i] < a[i]:
        b_cnt += (a[i] - b[i])

if a_cnt >= b_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()))
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:
n=int(input())
a=[int(j) for j in input().split()]
b=[int(j) for j in input().split()]
tmp=0
if tmp<0:
    print("No")
    exit()
for i,j in zip(a,b):
   if i>j:
       tmp+=j-i
   elif i<j:
       tmp+=(j-i)//2
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()))

diff = [a[i] - b[i] for i in range(N)]
plus = sum(filter(lambda x: x > 0, diff))
minus_even = sum(filter(lambda x: x < 0 and x % 2 == 0, diff))
minus_odd = sum(x + 1 for x in diff if x < 0 and x % 2 == 1)

# print(plus)

if plus * 2 + minus_even + minus_odd > 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

    cnt_a = 0
    cnt_b = 0
    for a, b in zip(A, B):
        if a > b:
            cnt_a += a - b
        elif a < b:
            cnt_b += (b - a) // 2

    if cnt_a > cnt_b:
        return "No"
    else:
        return "Yes"


print(solve())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = [a - b for a, b in zip(A, B)]
diff.sort()
k = 0
for d in diff:
  if d < 0:
    if d % 2 == 0:
      k += -d // 2
    else:
      k += -(d+1) // 2
  elif d == 0:
    continue
  else:
    k -= d

print(['Yes', 'No'][k<0])

Submission status: Accepted

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

def check(A,B):
    plus,minus = 0,0
    for i in range(N):
        diff = B[i]-A[i]
        if diff>0:
            plus += diff//2
        else:
            minus -= diff
    if plus >= minus:
        return True
    return False 

if check(A,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()))

def solve():
    delta = sum(B) - sum(A)
    if delta < 0:
        return False
    aup = [0] * N
    bup = [0] * N
    for i in range(N):
        d = B[i] - A[i]
        if d > 0:
            aup[i] = d // 2 + d % 2
            bup[i] = d % 2
        elif d < 0:
            bup[i] = -d
    #print('delta:', delta)
    #print('Aup:', aup)
    #print('Bup:', bup)
    adelta = delta - sum(aup)
    bdelta = delta - sum(bup)
    return adelta >= 0 and bdelta >= 0 and 2 * adelta == bdelta

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

Submission status: Accepted

Solution code:
import math

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

# 総和が等しくなることが必要条件なので、操作回数は sum(B) - sum(A)
def f():
    a_ctr = 0
    b_ctr = 0
    handle = sum(B) - sum(A)
    if handle < 0: return 0 # Aの総和が大きければ無理
    # A に足していく
    for i in range(N):
        if A[i] == B[i]:
            pass
        if A[i] > B[i]: 
            b_ctr += A[i] - B[i]
        else: 
            a_ctr += math.ceil((B[i] - A[i]) / 2)
            if (B[i] - A[i]) % 2 == 1: b_ctr += 1
    # print(a_ctr, b_ctr, handle)
    if a_ctr == b_ctr == handle: return 1
    if a_ctr < handle and b_ctr < handle and (handle - a_ctr) * 2 == handle - b_ctr: return 1
    return 0

if f():
    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()))
plus=0
minus=0
gomi=0
for i in range(N):
  if(a[i]-b[i]<0):
    minus+=((b[i]-a[i])//2)*2
  else:
    plus+=a[i]-b[i]
if(minus>=plus*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()))
numa = 0
numb = 0
num = sum(b)-sum(a)
for i in range(n):
    x = b[i] - a[i]
    if x > 0:
        numa += -(-x//2)
        if x % 2 == 1:
            numb += 1
    else:
        numb -= x
if (num-numa)*2 == num-numb and num >= numa:
    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()))

asum=sum(a)
bsum=sum(b)
if bsum<asum:
    print("No")
    exit()

ab=0
ba=0

for i in range(N):
    if a[i]<b[i]:
        ab+=(b[i]-a[i])//2
    else:
        ba+=a[i]-b[i]

if ab>=ba:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# a = 1,2,3
# b = 5,2,2
# 一度の操作でaは2、bは1増える
# b-aが1縮まる
# (bの合計 - aの合計)　が操作回数となる
# (bi - ai) を2で割って切り上げた数(=1を足して2で割って切り捨て)の累計が、必要な操作回数
# (ai - bi) の累計が、必要な操作回数
# この大きいほうが操作回数以下であればYes、なければNo

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

maxope=0
aope=0
bope=0
for i in range(N):
  maxope += B[i] - A[i]
  if B[i] > A[i]:
    aope += (B[i] - A[i] + 1) // 2
  elif A[i] > B[i]:
    bope += A[i] - B[i]

print(("No","Yes")[max(aope,bope) <= maxope])

Submission status: Accepted

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

# Ai ≤ Bi: Ai++ができるので，問題なし
#  - このとき (Bi - Ai) // 2回数は j として選んでOK
#
# Ai > Bi: i以外を選んで，Biを嵩上げする必要がある
# - 選んだjは A[j] + 2 ≤ B[j] が必要
# - Biは1ずつしか増えないので，これは-d回必要
#


diff = [b[i] - a[i] for i in range(n)]
count = 0
for d in diff:
    if d > 0: # Ai ≤ Bi
        count += d // 2  # 余る分
    else:     # Ai ≥ Bi
        count -= -d      # 嵩上げ

# 余る分が多ければ，嵩上げできる
if count >= 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()))

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

if(onesum<=twosum):
    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 = 0
for i in range(n):
    ai = a[i]
    bi = b[i]
    if ai < bi:
        c += (bi-ai)//2
    else:
        c -= (ai-bi)
print('Yes' if c >= 0 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):
    ans='No'
else:
    c=0
    d=0
    for a,b in zip(A,B):
        if a<b:
            d+=(b-a)//2+(b-a)%2
            c+=(b-a)%2
        else:
            c+=a-b
    if d>=c:
        ans='Yes'
    else:
        ans='No'
print(ans)

Submission status: Accepted

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

plus, minus = 0, 0
for i in range(n):
    if a[i] < b[i]:
        plus += (b[i] - a[i]) // 2
    if a[i] > b[i]:
        minus += (a[i] - b[i])
        
print('Yes' if minus <= plus 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):
    ans='No'
else:
    l=sum(B)-sum(A)
    cnt_a=l*2
    cnt_b=l
    for i in range(n):
        if A[i]>B[i]:
                cnt_b-=(A[i]-B[i])
        else:
            if (B[i]-A[i])%2==0:
                cnt_a-=(B[i]-A[i])
            else:
                cnt_a-=(B[i]-A[i])+1
                cnt_b-=1
    if cnt_a==cnt_b and cnt_a>=0:
        ans='Yes'
    else:
        ans='No'
print(ans)

Submission status: Accepted

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

nega = []
c = 0
gap = [0]*N
for i in range(N):
    gap[i] = a[i]-b[i]
    if gap[i] > 0:
        c += gap[i]
    elif gap[i] < 0:
        nega.append((-gap[i])//2)

nc = sum(nega)

if nc >= 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()))
A = sum(a)
B = sum(b)
sa = []
num = B-A
flag = True
for i in range(N):
    sa.append(b[i]-a[i])
    if a[i] != b[i]:
        flag= False
if flag:
    print('Yes')
else:
    if num <= 0:
        print('No')
    else:
        cnt = 0
        for i in range(N):
            if sa[i] > 0:
                cnt += sa[i]-sa[i]//2
        if cnt <= num:
            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()))

m = sum(B) - sum(A)
cnt_a, cnt_b = 0, 0

for a, b in zip(A, B):
    if a > b:
        cnt_b += 1
    elif a < b:
        if (b-a) % 2 == 0:
            cnt_a += (b-a)//2
        else:
            cnt_a += (b-a)//2 + 1

if max(cnt_a, cnt_b) <= m:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [i - j for i,j in zip(a,b)]
    
    p = 0
    m = 0
    for num in x:
        if num < 0:
            m += (-num//2) * 2
        else:
            p += num
    
    if 2 * p <= m:
        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()))
c = [_b-_a for _a, _b in zip(a, b)]
x, y = 0, 0
for _c in c:
    if _c > 0:
        x += _c//2
    else:
        y -= _c
if x >= y:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/apc001/tasks/apc001_b


import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
rr = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()

'''
aiとbiについて
ai<=biのとき→必ず等しくできる
ai>biのとき→ai-biをbiに加算してやっと等しくなれる。#Aのどこかに余分な2*(ai-bi)を加算しなくてはいけない(バラけてもokだけど)
余分な分を吸収してくれるような数字を探したい

→
まずai>biについてをai-biの合計n1を計算する(1を足した回数。これと同じ数2をAに足さないと行けない)
次に、ai+2<=biの各要素についてbi-ai(>=2)を計算し、n1を0に消費できるか計算する。
消費できればYes、できなればNo
(n1を0にした時点では数列は等しくなっていないが、ai<biについて1回以上の操作を追加することで必ず等しくできることが保証できる)
'''

n1 = 0  # bに+1する回数
for a, b in zip(A, B):
    if a > b:
        n1 += a - b

for a, b in zip(A, B):
    if a + 2 <= b:
        n1 -= (b - a) // 2


print("Yes" if n1 <= 0 else "No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    b = LI()
    suma = sum(a)
    sumb = sum(b)
    diff = sumb - suma
    tmp = 0
    for i in range(n):
        tmp += max((b[i] - a[i] + 1) // 2, 0)
    if diff >= tmp:
        print("Yes")
    else:
        print("No")
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

aPlus=0
bPlus=0

for i in range(n):
    if a[i]>b[i]:
        aPlus+=(a[i]-b[i])
    elif a[i]<b[i]:
        if (b[i]-a[i])%2==0:
            bPlus+=(b[i]-a[i])//2
        else:
            aPlus+=1
            bPlus+=(b[i]+1-a[i])//2

if aPlus<=bPlus:
    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=0
b=0
for i,j in zip(A,B):
    if j-i>=0:
        a += (j-i)//2
    else:
        b += i-j
if a >= 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()))

ope = sum(b) - sum(a)
var = 0

for i in range(n):
    if a[i] >= b[i]:
        var += a[i] - b[i]
    else:
        var += (b[i] - a[i])%2
if (ope-var)%2 == 0 and ope >= var:
    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, 0]
for ea, eb in zip(a, b):
    if ea > eb:
        cnt[1] += ea - eb
    else:
        cnt[0] += (eb - ea) // 2

if cnt[0] >= cnt[1]:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
import bisect
import heapq
import sys
import queue


input = sys.stdin.readline
sys.setrecursionlimit(100000)


class V:
    def __init__(self, f):
        self.f = f
        self.v = None

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n)

    def get(self):
        return self.v


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    N = int(input())
    A = read_list()
    B = read_list()

    KA = 0
    KB = 0
    for a, b in zip(A, B):
        if a == b:
            continue

        if a > b:
            KB += a - b
            continue

        if a % 2 != b % 2:
            KB += 1
            b += 1

        KA += (b - a) // 2

    print("Yes" if KA >= KB 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()))
a = 0
b = 0
for i in range(N):
    if A[i] > B[i]:
        a += A[i] - B[i]
    else:
        b += (B[i] - A[i])//2

print("Yes") if a <= b else print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
pos=[0]*n
s=0
for i in range(n):
  if b[i]-a[i]>=0:
    pos[i]=b[i]-a[i]
  else:
    s+=a[i]-b[i]
for p in pos:
  s-=p//2
if s<=0:
  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()]

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

Submission status: Accepted

Solution code:
def main():
    length = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    count_operation = 0
    for i in range(length):
        if a[i] < b[i]:
            count_operation -= (b[i] - a[i]) // 2
        else:
            count_operation += a[i] - b[i]
    print("Yes" if count_operation <= 0 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()))
allSousa = sum(B)-sum(A)
atob = 0
for a, b in zip(A, B):
  if a < b:
    atob += (b-a)//2+(b-a)%2
if allSousa < atob:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

x=sum(b)-sum(a)
y=0
for i in range(n):
    if a[i]<b[i]:
        y+=-((a[i]-b[i])//2)
print("No" if x<y else "Yes")

Submission status: Accepted

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

n = sum(b) - sum(a)
c = 0
for i in range(N):
    if a[i] < b[i]:
        c += (b[i] - a[i] + 2 - 1) // 2
print('Yes' if c <= n else 'No')

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
A = LI()
B = LI()
if sum(A) > sum(B):
    print('No')
    exit()
ret = 0
for i in range(n):
    if B[i] > A[i]:
        ret += (B[i] - A[i] + 1) // 2

if ret > sum(B) - sum(A):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
k = sum(b)-sum(a)
if k<0:
  print("No")
  exit()
ansa=0
ansb=0
for i in range(n):
  if b[i]<a[i]:
    ansb+=a[i]-b[i]
  else:
    re = b[i]-a[i]
    if re%2==0:
      ansa+=(b[i]-a[i])//2
    else:
      ansa+=(b[i]+1-a[i])//2
      ansb+=1
if (k-ansa)*2==k-ansb and 0<=k-ansa and 0<=k-ansb:
  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()))
x=0;y=0
for i in range(n):
  if a[i]<b[i]:
    x+=(b[i]-a[i])//2
  else:
    y+=(a[i]-b[i])
print('Yes' if x>=y else 'No')

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = LIST()
dif = sum(b) - sum(a)
if dif < 0:
    print('No')
    exit()
cnt1 = 0
cnt2 = 0
for i in range(n):
    tmp = b[i] - a[i]
    if tmp > 0:
        cnt2 += (tmp + 1) // 2
    else:
        cnt1 += -tmp
if dif < cnt1 or dif < cnt2:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

d = 0
c = 0
for x, y in zip(a, b):
  if x < y:
    d += (y - x) // 2
  else:
    c += x - y

print('Yes' if d >= c else 'No')

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]

cnt1 = 0 
cnt2 = 0

for i in range(N):
    if A[i] > B[i]:
        cnt1 += (A[i] - B[i])
    else:
        cnt2 += ((B[i]-A[i])//2)
        
if cnt1 <= cnt2:
    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()))

cluster_two = 0
cluster_one = 0

for i in range(N):
    if A[i] < B[i]:
        cluster_two += (B[i]-A[i])//2
    elif A[i] > B[i]:
        cluster_one += A[i]-B[i]

if cluster_two >= cluster_one:
    print('Yes')
else:
    print('No')

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()))

m = sum(B) - sum(A)
if m <= -1:
    print("No")
else:
    # print("m",m)
    M = [m, m]
    for i in range(n):
        di = B[i] - A[i]
        if di > 0:
            if di % 2 == 1:
                di += 1
                M[1] -= 1
            M[0] -= di//2
        else:
            M[1] -= -di
    # print(M)
    if M[0] >= 0 and M[1] >= 0 and M[0]*2 == M[1]:
        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()))

da = 0
db = 0
for i in range(n):
    if a[i] <= b[i]:
        da += (b[i] - a[i]) // 2
    else:
        db += a[i] - b[i]
        
if da >= db:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# B - Two Arrays
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum_a=sum(a)
sum_b=sum(b)

a_cnt,b_cnt=0,0

for aa,bb in zip(a,b):
    if aa>bb:
        a_cnt+=aa-bb
    elif aa<bb:
        b_cnt+=(bb-aa)//2

print('Yes') if a_cnt<=b_cnt 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()]

"""
操作X: aに1を足す
操作Y: aに2を足す
操作Z: bに1を足す

問題文の操作はXと一致する。
(X = Y + Z)

if Yの回数 <= Zの回数:
    Yes (不足分はXで処理できる)
else:
    No
"""

cnt = 0

for i in range(N):
    a, b = A[i], B[i]

    # 操作Z
    if a > b:
        Z = a - b
        B[i] += Z
        cnt += Z

for i in range(N):
    # 操作Y
    if A[i] < B[i]:
        Y = (B[i] - A[i]) // 2
        A[i] += 2 * Y
        cnt -= Y

        # 操作X
        if A[i] < B[i]:
            A[i] += 2
            B[i] += 1

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

Submission status: Accepted

Solution code:
from sys import stdin
from math import ceil
def main():
	readline=stdin.readline
	N=int(readline())
	a=list(map(int,readline().split()))
	b=list(map(int,readline().split()))

	count=0
	for i in range(N):  #一旦、任意のiについてa_iをb_iよりも大きくする。
		if a[i]<b[i]:   #その時の回数をcountとする。
			c=ceil((b[i]-a[i])/2)
			count+=c
			a[i]+=2*c

	for i in range(N):  #count以内の回数でbも大きくしていく。
		if b[i]<a[i]:   #上の手順後にa<=bならa_i<b_iのiについて
			d=a[i]-b[i] #a_iとb_iを同時に増やしていけばa=bにすることができ、
			b[i]+=d     #a>bなら逆転不可能でa=bにすることはできない。
			count-=d

	if count>=0:
		print("Yes")
	else:
		print("No")

if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
from sys import stdin
from math import ceil
def main():
	readline=stdin.readline
	N=int(readline())
	a=list(map(int,readline().split()))
	b=list(map(int,readline().split()))
	a_count=0
	s=sum(b)-sum(a)

	for i in range(N):
		if a[i]<b[i]:
			a_count+=ceil((b[i]-a[i])/2)

	if a_count<=s:
		print("Yes")
	else:
		print("No")

if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [A[i] - B[i] for i in range(N)]
    sumA = sum(A)
    sumB = sum(B)
    addA, addB = 0, 0
    for i, c in enumerate(C):
        if c > 0: addB += c
        else: addA += (-1 * c + 1) // 2
    if addA > sumB - sumA or addB > sumB - sumA: print("No")
    else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    op = sum(B) - sum(A)
    D = [(b-a+1)//2 if b > a else 0 for a, b in zip(A, B)]
    print("Yes" if op >= sum(D) 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()))

a_sum, b_sum = sum(A), sum(B)
turns = b_sum - a_sum
a_small = 0
b_small = 0
for a, b in zip(A,B):
    if a < b:
        a_small += (b - a + 1) // 2
    else:
        b_small += a - b
if a_small <= turns and b_small <= turns:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
x, y = sum(X), sum(Y)
import sys
if y < x:
    print("No")
    sys.exit()
kx=ky=y-x
for i in range(N):
    if Y[i] > X[i]:
        kx -= -(-(Y[i]-X[i])//2)
        X[i] = Y[i] + (Y[i]-X[i])%2
for i in range(N):
    if X[i] > Y[i]:
        ky -= X[i]-Y[i]
        Y[i] = X[i]
#print(X, Y, kx, ky, y-x)
if kx <0 or ky<0:
    print("No")
elif kx*2 != ky:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a, b = [list(map(int, input().split())) for i in range(2)]

ap = bp = 0
for i in range(n):
        if a[i]>b[i]: bp += a[i]-b[i]
        else:
                if (b[i]-a[i])%2: bp += 1
                ap += (b[i]-a[i]+1)//2
print("YNeos"[ap<bp::2])

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)
res=0
for i in range(n):
  if b[i]>a[i]:
    res += (b[i]-a[i]+1)//2
if res > t:
  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()]

can = sum(b)-sum(a)
actA,actB = 0,0
for i in range(N):
    diff = b[i]-a[i]
    if diff==0:continue
    if diff>0:
        actA+=(diff+1)//2
        actB+=diff%2
    else:
        actB+=(-diff)
leftA = can-actA
leftB = can-actB
print("Yes" if leftA>=0 and leftA*2==leftB else "No")

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    
    if sum(a) > sum(b):
        print("No")
    else:
        do = sum(b)-sum(a)
        ca,cb = 0,0
        for x,y in zip(a,b):
            if x > y:
                cb += x-y
            else:
                if (y-x)%2 == 0:
                    ca += (y-x)//2
                else:
                    ca += (y+1-x)//2
                    cb += 1
        if ca-cb >= 0:
            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()))
a=0
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 b<a:
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

# 最大試行回数
n = B - A
r_a = 0
r_b = 0
cnt = 0

for i, j in zip(a, b):
    if i < j:
        if (j - i) % 2 == 1:
            if r_b:
                r_b -= 1
            else:
                cnt += 1
                r_a += 1
            j += 1
        d = (j - i) // 2
        if d <= r_a:
            r_a -= d
        else:
            d -= r_a
            r_a = 0
            cnt += d
            r_b += d
    elif i > j:
        d = i - j
        if d <= r_b:
            r_b -= d
        else:
            d -= r_b
            r_b = 0
            cnt += d
            r_a += d

if cnt <= n:
    print('Yes')
else:
    print('No')