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:
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if sum(A) > sum(B):
        print('No')
        exit()
    
    cnt = 0
    for i in range(N):
        if B[i] > A[i]:
            cnt += (B[i] - A[i]) // 2
        else:
            cnt -= (A[i] - B[i])

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    pos = 0
    neg = 0
    for i in range(N):
        pos += max(a[i]-b[i],0)
        neg += abs(min(a[i]-b[i],0))//2
    if  neg >= pos:
        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()))

cnt = 0
for a, b in zip(A, B):
    if a > b:
        cnt += (a-b)
    else:
        cnt -= (b-a)//2

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = inpl()
res = 0
for x,y in zip(a,b):
    if x > y:
        res += x-y
    elif x < y:
        res -= (y-x)//2
# print(res)
print('No' if res > 0 else 'Yes')

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)
if sa>sb:
    print("No")
else:
    d1 = 0
    d2 = 0
    for i in range(N):
        if A[i]>B[i]:
            d1 += A[i]-B[i]
        elif B[i]>A[i]:
            d2 += (B[i]-A[i])//2
    if d2>=d1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
Bs = list(mapint())

ap = 0
bp = 0
for a, b in zip(As, Bs):
    if a>b:
        ap += a-b
    else:
        bp += (b-a)//2
if ap>bp:
    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()))
sa=sum(a)
sb=sum(b)
if sb<sa:
  print("No")
  exit(0)
husoku_a=0
husoku_b=0
for aa,bb in zip(a,b):
  if bb<aa:
    husoku_a+=aa-bb
  elif bb>aa:
    husoku_b+=(bb-aa)//2

if husoku_a<=husoku_b:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def solve():
    n = getN()
    anums = getList()
    bnums = getList()
    # if sum(anums) > sum(bnums):
    #     print("No")
    #     return

    pair = []
    for i, j in zip(anums, bnums):
        pair.append((i, j))

    pair.sort(key=lambda x:- x[0] + x[1])
    # print(pair)
    kosi = 0
    for a,b in pair:
        # a += kosi
        if b >= a:
            kosi -= (b-a) // 2 * 2
        else:
            kosi += (a - b) * 2
        # print(a, b, kosi)

    if kosi > 0:
        print("No")
        return
    else:
        print("Yes")
        return


def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
    if a[i] > b[i]:
        res -= a[i] - b[i]
    else:
        res += (b[i] - a[i]) // 2
if res >= 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()))

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)

cnt = sum(b) - sum(a)
if cnt1 <= cnt and cnt2 <= 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()))

x, y = 0, 0
for i in range(n):
    dif = b[i] - a[i]
    if dif > 0:
        x += dif // 2
    else:
        y += -dif

print("Yes" if x >= y else "No")

Submission status: Accepted

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

    suma = 0
    dab = 0
    dba = 0
    for i in range(n):
        suma += b[i]-a[i]
        if a[i] < b[i]:
            dab += math.ceil((b[i]-a[i])/2)
        else:
            dba += a[i]-b[i]
    if max(dba, dab) > suma:
        print("No")
    else:
        print("Yes")
resolve()

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')
    exit()
else:
    cnt = sum(B)-sum(A)
a_tmp = 0
b_tmp = 0
for i in range(N):
    if A[i] == B[i]:
        continue
    if cnt == 0:
        print('No')
        exit()
    if A[i] > B[i]:
        b_tmp += A[i]-B[i]
    else:
        if (B[i]-A[i]) % 2 == 0:
            a_tmp += (B[i]-A[i]) // 2
        else:
            a_tmp += ((B[i]-A[i]) // 2)+1
            b_tmp += 1
if a_tmp > cnt or b_tmp > cnt:
    print('No')
    exit()
if (cnt-a_tmp)*2 == cnt-b_tmp:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

    cnt_P = 0
    cnt_N = 0

    for i in range(N):
        diff = B[i]-A[i]
        if diff>0:
            cnt_P += diff//2
        elif diff<0:
            cnt_N += -diff

    if sum(A)<=sum(B) and cnt_P>=cnt_N:
        ret = 'Yes'
    else:
        ret = 'No'

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    plus2_cnt = 0
    neg_cnt = 0
    for i in range(N):
        diff = b[i] - a[i]
        if diff >= 0:
            plus2_cnt += diff // 2
        else:
            neg_cnt += abs(diff)
    
    if plus2_cnt >= neg_cnt:
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def do():
    n = int(input())
    data = list(map(int, input().split()))
    datb = list(map(int, input().split()))
    sa = sum(data)
    sb = sum(datb)
    if sb < sa:
        print("No")
        return 0
    diffcnt = sb - sa
    cnt1 = 0
    cnt2 = 0
    import math
    for i in range(n):
        if data[i] > datb[i]:
            cnt1 += data[i] - datb[i]
        if data[i] < datb[i]:
            cnt2 += math.ceil((datb[i] - data[i]) / 2)
    if cnt2 <= diffcnt:
        print("Yes")
    else:
        print("No")
    #print(diffcnt, cnt1, cnt2)


do()

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sum(b)-sum(a)
d=0
for i in range(n):
 if a[i]>b[i]:d+=a[i]-b[i]
 elif a[i]%2!=b[i]%2:d+=1
print("No"if c<d else"Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b = l()
num = sum(b)-sum(a)
cnt1 = 0
cnt2 = 0
for i in range(N):
    if a[i] > b[i]:
        cnt1 += a[i]-b[i]
    if a[i] < b[i]:
        cnt2 += math.ceil((b[i]-a[i])/2)
if cnt1 > num or cnt2 > num:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b = l()
num = sum(b)-sum(a)
cnt1 = 0
cnt2 = 0
for i in range(N):
    if a[i] > b[i]:
        cnt1 += a[i]-b[i]
    if a[i] < b[i]:
        cnt2 += (b[i]-a[i]-1)//2+1
if cnt1 > num or cnt2 > num:
    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 = sum(a)
b_sum = sum(b)

if a_sum > b_sum:
    print("No")
    exit(0)

less_a_cnt = 0
less_b_cnt = 0

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

if less_a_cnt < less_b_cnt:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  divisors.sort()
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()
B = IL()
C = [-(-(A[i]-B[i])//2)*2 if A[i]-B[i]<0 else A[i]-B[i]  for i in range(N)]
C.sort()

p = bisect.bisect(C,0)
C1 = C[:p]
C2 = C[p:]

if sum(C2)*2 + sum(C1) > 0:
  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()))
c = 0
for i in range(n):
    if a[i] < b[i]:
        c += -((a[i]-b[i])//2)
        a[i] += -((a[i]-b[i])//2) * 2
d = 0
for i in range(n):
    if b[i] < a[i]:
        d += a[i]-b[i]
if c == d:
    ans = 1
elif c < d:
    ans = 0
elif d < c:
    ans = 1
print(["No","Yes"][ans])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
print('YNeos'[sum(B)-sum(A)<sum(max(0,(b-a+1)//2)for a,b in zip(A,B))::2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
print('Yes' if sum(B)-sum(A) >= sum(max(0,(b-a+1)//2) for a,b in zip(A,B)) else 'No')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
K = sum(B)-sum(A)
for a,b in zip(A,B):
    if a < b:
        K -= (b-a+1)//2
print('Yes' if K >= 0 else 'No')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
Ka = sum(B)-sum(A)
Kb = Ka
for a,b in zip(A,B):
    if a < b:
        Ka -= (b-a+1)//2
print('Yes' if Ka >= 0 and Kb >= 0 else 'No')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
Ka = sum(B)-sum(A)
Kb = Ka
for a,b in zip(A,B):
    if a > b:
        Kb -= a-b
    else:
        if (b-a)%2:
            Ka -= (b-a+1)//2
            Kb -= 1
        else:
            Ka -= (b-a)//2
print('Yes' if Ka >= 0 and Kb >= 0 else 'No')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
Ka = sum(B)-sum(A)
Kb = Ka
for a,b in zip(A,B):
    if a > b:
        Kb -= a-b
    else:
        if (b-a)%2:
            Ka -= (b-a+1)//2
            Kb -= 1
        else:
            Ka -= (b-a)//2
print('Yes' if Ka*2 == Kb and Ka >= 0 and Kb >= 0 else 'No')

Submission status: Accepted

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

a_gap = 0
b_gap = 0
for i in range(n):
    if A[i]>B[i]:
        a_gap+=A[i]-B[i]
    if A[i]<B[i]:
        b_gap+=(B[i]-A[i])//2

if b_gap-a_gap<0:
    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()))
cnt = 0
for a_, b_ in zip(a, b):
    if a_ > b_:
        cnt += a_ - b_
    else:
        cnt -= (b_ - a_) // 2
if cnt <= 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
B = list(map(int, sys.stdin.readline().rstrip().split()))

if A == B:
    print("Yes")
    exit()
diff = [a - b for a, b in zip(A, B)]
minus = []
plus = []
for d in diff:
    if d < 0:
        minus.append(-d)
    elif d > 0:
        plus.append(d)

total = 2 * sum(plus)
minus.sort()
while total:
    if not minus or sum(minus) < total:
        break
    if minus[-1] >= total:
        total = 0
    else:
        if minus[-1] % 2 == 1:
            total -= minus[-1] - 1
        else:
            total -= minus[-1]
        minus.pop()
else:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

sum1=0
sum2=0

for i,j in zip(a,b):
  if i>j:
    sum1+=(i-j)
  elif i<j:
    sum2+=(j-i)//2

print('Yes' if sum1<=sum2 else 'No')

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):
    dif = b[i]-a[i]
    if dif>0:x += dif//2
    else:y += -dif

print('Yes' if x>=y else 'No')

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    A = LMIIS()
    B = LMIIS()
    GA = deque() #ai > bi の組
    GB = deque()
    for a,b in zip(A,B):
        if a > b:
            GA.append(a-b)
        elif a < b:
            GB.append(b-a)
    
    for ga in GA:
        tmp = ga
        while GB:
            gb = GB.popleft()
            if gb >= tmp*2:
                GB.append(gb-tmp*2)
                break
            else:
                tmp -= gb//2
        if len(GB) == 0:
            print('No')
            return
    print('Yes')
        
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arra=limii()
arrb=limii()

times=sum(arrb)-sum(arra)

plus=0
minus=0

for i,j in zip(arra,arrb):
    if j-i>0:
        plus+=(j-i)//2
    elif j-i<0:
        minus+=i-j

if plus>=minus:
    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()))
am = 0
bm = 0
for i in range(n):
    if a[i] == b[i]:
        continue
    elif a[i] > b[i]:
        bm += a[i] - b[i]
    else:
        am += (b[i] - a[i] + 1) // 2
        if (b[i] - a[i]) % 2:
            bm += 1
if am - bm >= 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    a = list(map(int, rl().split()))
    b = list(map(int, rl().split()))
    
    d = sum(b) - sum(a)
    cnt = 0
    for i in range(N):
        if a[i] < b[i]:
            cnt += (b[i] - a[i] + 1) // 2
    if cnt <= d:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    # print(N, A, B)
    expected = sum(B) - sum(A)
    if expected < 0:
        print('No')
        return
    add_a, add_b = 0, 0
    for i in range(N):
        a, b = A[i], B[i]
        if a > b:
            add_b += a - b
        elif a < b:
            add_a += (b - a + 1) // 2
    if add_a <= expected and add_b <= expected:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
aa = map(int, input().split())
bb = map(int, input().split())

d = 0
for a, b in zip(aa, bb):
    if a >= b:
        d += a - b
    else:
        d -= (b - a) // 2

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

Submission status: Accepted

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

adif,bdif=0,0
for i in range(N):
    if a[i]<b[i]:
        adif+=(b[i]-a[i])//2
    elif a[i]>b[i]:
        bdif+=a[i]-b[i]
if bdif<=adif:
    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)

ka=0
kb=0
for i in range(n):
    if A[i]>B[i]:
        kb+=A[i]-B[i]
    elif A[i]<B[i]:
        ka+=(B[i]-A[i]+1)//2
        kb+=(B[i]-A[i])%2

if k>=ka and k>=kb:
    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()))
kai=sum(b)-sum(a)
if kai<0:
    for i in range(n):
        if a[i]!=b[i]:print("No");exit()
    print("Yes")
else:
    akai=kai
    bkai=kai
    for i in range(n):
        if a[i]==b[i]:continue
        if a[i]>b[i]:
            bkai-=a[i]-b[i]
        else:
            if (b[i]-a[i])%2:
                b[i]+=1
                bkai-=1
            akai-=(b[i]-a[i])//2
        if akai<0 or bkai<0:print("No");exit()
    print("Yes")if bkai==2*akai else print("No")

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
need1 = 0
need2 = 0
for i in range(n):
    s = B[i]-A[i]
    if s < 0:
        need1 -= s
    else:
        need2 += s//2
if need1 > need2:
    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()))
c = [a[i]-b[i] for i in range(N)]
d=sum(b)-sum(a)   #c回試行する
if d<0:
  print("No")
  exit()
  
must=0
cnt=0
for num in c:
  if num>0:
    must += abs(num)
  if num*(-1) >= 2:
    cnt += (-1)*num//2
if must>d:
  print("No")
  exit()

#nokori = d-must
#print(must,nokori,cnt)

if cnt<must:
  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()))

na, nb = 0, 0

suma = sum(a)
sumb = sum(b)
jdg = False

for i in range(N):
    while a[i]!= b[i]:
        if suma + na > sumb + nb:
            jdg = True
            break
        if i == N - 1:
            a[i] += na
            b[i] += nb
            if a[i] > b[i]:
                jdg = True
            break
        if a[i] > b[i]:
            ab = a[i] - b[i]
            if nb < ab:
                na += 2 * (ab - nb)
                nb = 0
            else: nb -= ab
            sumb += ab
            b[i] += ab
        else:
            ba = b[i] - a[i]
            if na < ba:
                nb += (ba - na + 1) // 2
                na = 0
            else: na -= ((ba+1)//2)*2
            if nb > 0: nb -= ba%2
            else: na += 2 * (ba%2)
            suma += ((ba+1)//2)*2
            sumb += ba%2
            a[i] += ((ba+1)//2)*2
            b[i] += ba%2
    if jdg: break
print('No' if jdg else 'Yes')

Submission status: Accepted

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

d=[]
for i in range(N):
    d.append(a[i]-b[i])

cnt=-sum(d)
p=0
n=0
for j in range(N):
    if d[j]>0:
        p+=d[j]
    if d[j]<0:
        n+=-d[j]-(-d[j])%2
if n>=p*2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = ZZ()
    B = ZZ()
    if A == B:
        print('Yes')
        return
    sa, sb = sum(A), sum(B)
    if sa >= sb:
        print('No')
        return

    numDo = sb - sa
    x = y = 0
    for a, b in zip(A, B):
        if a > b: x += (a - b)
        elif a < b: y += (b-a+1)//2
    print('Yes' if x <= numDo and y <= numDo else 'No')

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque
inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
suma = sum(a)
sumb = sum(b)
count = sumb-suma
suba = 0
subb = 0
if count < 0:
    print('No')
    sys.exit()
for i in range(n):
    if a[i] > b[i]:
        suba+=abs(a[i]-b[i])
    else:
        subb+=(abs(a[i]-b[i])+1)//2
if max(suba, subb) <= count:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()
B = LI()

x = 0
y = 0
for i in range(N):
    a = A[i]
    b = B[i]
    if a < b:
        if (b-a)%2 == 0:
            x += (b-a)//2
        else:
            x += (b-a)//2 + 1
            y += 1
    else:
        y += a-b

if x < y:
    print('No')
    exit()
count = 2*x-y

if count == sum(B)-sum(A) and 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()))
s = 0
t = 0
for i in range(n):
	k = b[i] - a[i]
	if k < 0:
		s += -k
	elif k > 0:
		t += k//2
if s <= t:
	print("Yes")
else:
	print("No")