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: Time Limit Exceeded

Solution code:
def main():
    import sys
    import time
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    B = [int(x) for x in input().strip().split()]
    AB = [a - b for a, b in zip(A, B)]
    if A == B:
        print('Yes')
        exit()
    elif sum(AB) > 0:
        print('No')
        exit()
    ai = 0
    bi = 0
    while ai < N and bi < N:
        if ai != N-1 and A[ai] >= B[ai]:
            ai = min(N-1, ai+1)
            continue
        if (A[bi] - B[bi]) % 2 == 1:
            A[ai] += 2
            B[bi] += 1
            continue
        if bi != N-1 and A[bi] <= B[bi]:
            bi = min(N-1, bi+1)
            continue
        cnt = min(int((B[ai]-A[ai])/2 + .5), max(1, A[bi]-B[bi]))
        A[ai] += cnt * 2
        B[bi] += cnt
        if ai == N-1 and bi == N-1:
            if A[ai] - B[bi] == 1:
                A[ai] += 2
                B[bi] += 1
            break
    
    if A == B:
        print('Yes')
    else:
        print('No')




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    sys.stdin.readline()
    a = list(map(int, sys.stdin.readline().split()))
    b = list(map(int, sys.stdin.readline().split()))
    N = len(a)

    w = []
    for i in range(N):
        if a[i] == b[i]:
            continue
        w.append((a[i], b[i]))

    cnt = 0
    while w:
        cnt += 1
        if cnt > 10000:
            print('No')
            return
        a_min_idx, a_diff, b_min_idx, b_diff = 0, b[0] - a[0], 0, a[0] - b[0]
        for i, (ai, bi) in enumerate(w):
            if ai < bi and bi - ai > a_diff:
                a_diff = bi - ai
                a_min_idx = i
            if bi < ai and ai - bi > b_diff:
                b_diff = ai - bi
                b_min_idx = i
        w[a_min_idx] = (w[a_min_idx][0] + 2, w[a_min_idx][1])
        w[b_min_idx] = (w[b_min_idx][0], w[b_min_idx][1] + 1)
        if w[a_min_idx][0] == w[a_min_idx][1]:
            del w[a_min_idx]
            if b_min_idx == a_min_idx:
                b_min_idx = -1
            elif a_min_idx < b_min_idx:
                b_min_idx -= 1
        if b_min_idx >= 0 and w[b_min_idx][0] == w[b_min_idx][1]:
            del w[b_min_idx]
    print('Yes')
        

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

alist = [a for a in map(int, input().split())]
blist = [b for b in map(int, input().split())]

for i in range(n-1):
    while not (alist[i] == blist[i]):
        if alist[i] > blist[i]:
            alist[i+1] += 2
            blist[i] += 1
        elif alist[i] < blist[i]:
            alist[i] += 2
            blist[i+1] += 1

if alist[-1] == blist[-1]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
from queue import PriorityQueue


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

A_sum = sum(A)
B_sum = sum(B)
diff = B_sum - A_sum
if diff < 0:
    print("No")
    exit()

Aq = PriorityQueue()
Bq = PriorityQueue()
for a in A:
    Aq.put((a, a))
for b in B:
    Bq.put((b, b))

cnt = 0

while cnt <= diff and (not Aq.empty()) and (not Bq.empty()):
    _, a = Aq.get()
    _, b = Bq.get()
    if a < b:
        ne_a = a + 2
        ne_b = b + 1
        Aq.put((ne_a, ne_a))
        Bq.put((ne_b, ne_b))
        cnt += 1

if Aq.empty() and Bq.empty():
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
if sum(a) > sum(b) :
  print('No')
else :
  for i in range(n-1) :
    while a[i] != b[i] :
      if a[i] < b[i] :
        a[i] += 2
        b[i+1] += 1
      else :
        a[i+1] +=2
        b[i] += 1
  if a[n-1] == b[n-1] :
    print('Yes')
  else :
    print('No')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(n) :
  if i == n -1 :
    if a[i] == b[i] :
      print('Yes')
    else :
      print('No')
    break
  else :
    while a[i] != b[i] :
      if a[i] < b[i] :
        a[i] += 2
        b[i+1] += 1
      else :
        a[i+1] +=2
        b[i] += 1

Submission status: Time Limit Exceeded

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)]
if sum(c) > 0:
    print("No")
    exit()
while sum(c) < 0:
    i,j,m = 0,0,0
    f_i,f_j = False,False
    for k in range(n):
        if c[k] == -1 and not f_i:
            i = k
            j = k
            f_i = True
            f_j = True
        if c[k] < -1 and not f_i:
            i = k
            f_i = True
        if c[k] > 0 and not f_j:
            j = k
            f_j = True
        if c[k] == 0:
            m = k
        if f_i and f_j:
            break
    if not f_j:
        j = m
    c[i] += 2
    c[j] -= 1
if len(list(filter(lambda x:x!=0, c))) > 0:
    print("No")
else:
    print("Yes")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cl = [0 for n in range(N)]
res = False

for n in range(N):
    cl[n] = al[n] - bl[n]

if sum(cl) > 0:
    res = False
else:
    while True:
        cl = sorted(cl)
        if sum(cl) > 0:
            res = False
            break
        elif cl[N-1] <= 0:
            res = True
            break
        cl[0] += 2
        cl[N-1] += -1

if res:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

flag = "Yes"
for i in range(N):
   A_max = max(a)
   B_max = max(b)
   if A_max > B_max:
      flag = "No"
   else:
      del a[a.index(A_max)]
      del b[b.index(B_max)]

print(flag)

Submission status: Accepted

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

sa=[a[i]-b[i] for i in range(n)]

p=0
m=0
for i in sa:
  if 0<i:
    m+=i
  else:
    p+=abs(i)//2

if m<=p:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:

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

    cnt_A = 0
    cnt_B = 0
    for i in range(N):
        if A[i] > B[i]:
            cnt_A += A[i] - B[i]
        if B[i] > A[i]:
            cnt_B += (B[i] - A[i]) // 2

    if cnt_B >= cnt_A:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt1=[0]*n
cnt2=[0]*n
for i in range(n):
    if a[i]>b[i]:
        cnt2[i]=a[i]-b[i]
    else:
        num4=b[i]-a[i]
        cnt1[i]=-(num4//-2)
        cnt2[i]=num4%2
num5=abs(sum(a)-sum(b))
if max(sum(cnt1),sum(cnt2))+abs(sum(cnt1)-sum(cnt2))<=num5:
    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()))

cnt1 = 0
cnt2 = 0
for i in range(N):
    if a[i] > b[i]:
        cnt2 += a[i] - b[i]
    else:
        cnt1 += (b[i] - a[i] + 1) // 2
        cnt2 += (b[i] - a[i]) % 2

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
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")
else:
    cnt=sb-sa
    resa=0
    resb=0
    for i in range(n):
        if b[i]<a[i]:
            resa+=a[i]-b[i]
        else:
            resb+=math.ceil((b[i]-a[i])/2)
    if resa>cnt or resb>cnt:
        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()))

if sum(a) > sum(b):
  print ('No')
  exit()
elif sum(a) == sum(b):
  for i in range(n):
    if a[i] != b[i]:
      print ('No')
      exit()
  print ('Yes')
  exit()

s = sum(b)-sum(a)
c = 0
for i in range(n):
  if a[i] < b[i]:
    c += math.ceil((b[i]-a[i])/2)
if c > s:
  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()))

biggerA = 0
biggerB = 0
for ai, bi in zip(a, b):
  if ai > bi:
    biggerA += ai - bi
  if ai < bi:
    biggerB += (bi - ai) // 2
if biggerB >= biggerA:
  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()))
    D = [a - b for a, b in zip(A, B)]
    # [0, 0, ..., 0]の数列に対し、「どれかを-2」「どれかを+1」をk回ずつやってDを作れるか？
    cnt_m2 = 0
    cnt_p1 = 0
    # 必要最低限な個数を計算
    for d in D:
        if d < 0:
            if d % 2 == 0:
                cnt_m2 += abs(d) // 2
            else:
                cnt_m2 += (abs(d) + 1) // 2
                cnt_p1 += 1
        elif d > 0:
            cnt_p1 += d
    # 基本的に「-2の回数」==「+1の回数」にできればYes。
    # ちなみに同じ数に対する操作として「-2の回数」:「+1の回数」=1:2 ならプラマイゼロで相殺されるので、
    # 相殺可能な操作を足して「-2の回数」==「+1の回数」にできればYes。
    # つまり cnt_m2 >= cnt_p1 ならYes。
    if cnt_m2 >= cnt_p1:
        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()))
k = sum(b)-sum(a)
c,d = 0,0
for i in range(n):
  e = b[i]-a[i]
  if e<=0:
    d -= e
  else:
    c+= (e+1)//2
    d+= e%2 
print("Yes" if k>=c and k>=d else "No")

Submission status: Accepted

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

plus_2 = 0
minus = 0
for a, b in zip(A, B):
    if a < b:
        plus_2 += (b-a)//2
    else:
        minus += a-b

if plus_2 >= minus:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

capacity=0
for i in range(n):
    capacity+=max(0,b[i]-a[i]-(b[i]-a[i])%2)

for i in range(n):
    if a[i]>b[i]:
        capacity-=(a[i]-b[i])*2

if capacity>=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()))

pos = 0
neg = 0

for i in range(n):
    dif = b[i]-a[i]

    if dif > 0:
        pos += dif//2
    elif dif < 0:
        neg += dif

neg = abs(neg)

print("Yes" if pos >= neg else "No")

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
aa=sum(A) ; bb=sum(B)
if aa>bb:
    print("No");exit()
if aa==bb:
    if A==B:print("Yes");exit()
    print("No");exit()

C=[i-j for i,j in zip(A,B)]
D=[[0,0]]*n
for i in range(n):
    if C[i]>=0:
        D[i]= [0,C[i]]
    else:
        D[i]= [(-C[i]+ (C[i]%2))//2 , C[i]%2]
if sum([i[0] for i in D])>= sum([l[1] for l in D]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
A=lint()
B=lint()
k=sum(B)-sum(A)
opa=opb=0
for a,b in zip(A,B):
    opa+=max(0,(b-a+1)//2)
    opb+=max(0,a-b)
judge(opa<=k and opb<=k)

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)

one = 0
two = 0

for i in range(N):
    if A[i] > B[i]:
        one += A[i]-B[i]
    if A[i] < B[i]:
        two += (B[i]-A[i])//2
        if (B[i]-A[i])%2 == 1:
            one += 1

if one<=x and two<=x:
    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()))
sum_diffA = 0
sum_diffB = 0
for i, (ai, bi) in enumerate(zip(A,B)):
    if ai == bi:
        continue
    elif ai > bi:
        sum_diffB += (ai - bi)
    elif ai < bi:
        diffA = (bi - ai)
        sum_diffA += diffA // 2 + diffA % 2
        sum_diffB += diffA % 2
if sum_diffA >= sum_diffB:
    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=0
for i in range(N):
   if A[i]>B[i]:
      A_sum+=A[i]-B[i]
   elif A[i]<B[i]:
      A_sum-=(B[i]-A[i])//2
if A_sum<=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_s=sum(a)
b_s=sum(b)
if a_s>b_s:
    print("No")
    exit()
count=b_s-a_s
temp1=0
temp2=0
for i in range(n):
    if a[i]>=b[i]:
        temp1+=a[i]-b[i]
    else:
        if a[i]%2==b[i]%2:
            temp2+=(b[i]-a[i])//2
        else:
            temp1+=1
            temp2+=(b[i]+1-a[i])//2

if temp1>count or temp2>count:
    print("No")
    exit()
if (count-temp1)==(count-temp2)*2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus, minus = 0, 0

if n == 1:
    if a[0] <= b[0]:
        print('Yes')
    else:
        print('No')
    sys.exit()

for i, j in zip(a, b):
    num = j-i
    if num >= 0:
        plus += num//2
    else:
        minus -= num
        
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()))
c = []
a_sum = 0
b_sum = 0
for i in range(n):
    c.append(b[i]-a[i])
    if c[i] < 0:
        b_sum += c[i]
    else:
        a_sum += c[i]//2

if a_sum < abs(b_sum):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    CNT = 0
    for i in range(N):
        a = A[i]
        b = B[i]
        if a < b:
            CNT += (b-a+1)// 2
    sa = sum(A)
    sb = sum(B)
    if sa > sb:
        print('No')
    elif sb - sa >= CNT:
        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=0
ne=0
for i in range(n):
  c+=max((b[i]-a[i])//2,0)
  ne+=max(a[i]-b[i],0)

print("Yes" if c>=ne else "No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [B[i] - A[i] for i in range(N)]
K = sum(B) - sum(A)
flag = True
if(K < 0):
    flag = False

if(flag):
    p1 = K
    m2 = K
    for i in range(N):
        if(C[i] == 0):
            pass
        elif(C[i] < 0):
            p1 += C[i]
        elif(C[i] > 0):
            if(C[i] % 2 == 0):
                m2 -= C[i] // 2
            else:
                m2 -= C[i] // 2 + 1
                p1 -= 1
    if(p1 < 0 or m2 < 0):
        flag = False
    else:
        if(p1 == 2*m2):
            flag = True
        else:
            flag = False
    #print(K,p1,m2)
#print(C)
if(flag):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ca=cb=0
for a,b in zip(A,B):
    ca+=max(0,(b-a)//2)
    cb+=max(0,a-b)

print('YNeos'[ca<cb::2])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    return N, A, B


def solve(N, A, B):
    # 正負の相殺操作ができる回数
    k = 0
    # 負数の合計
    m = 0
    for a, b in zip(A, B):
        d = b - a
        if d > 0:
            k += d // 2
        elif d < 0:
            m -= d
    return "Yes" if k >= m else "No"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    B = LI()

    a = sum(A)
    b = sum(B)
    t = b - a
    if t < 0:
        print('No')
        return 
    a_cnt = 0
    b_cnt = 0
    for i in range(N):
        a = A[i]
        b = B[i]
        if a > b:
            c = a - b
            b_cnt += c
        elif a < b:
            c = b - a
            if c % 2 == 0:
                a_cnt += (c // 2)
            else:
                a_cnt += (c // 2) + 1
                b_cnt += 1
    # print(a_cnt, b_cnt, t - a_cnt, t - b_cnt)
    a_left = t - a_cnt
    b_left = t - b_cnt
    if a_left >= 0 and b_left >= 0:
        if a_left * 2 == b_left:
            print('Yes')
    else:
        print('No')

                
            

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A_sum=0
for i in range(N):
   if A[i]>B[i]:
      A_sum+=A[i]-B[i]
   elif A[i]<B[i]:
      A_sum-=(B[i]-A[i])//2
if A_sum<=0:
   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()))
    suma = sum(a)
    sumb = sum(b)
    k = sumb - suma

    s = [0] * N
    t = [0] * N
    for i in range(N):
        diff = a[i] - b[i]
        if diff < 0:
            if diff % 2 == 1:
                s[i] += (abs(diff)+1)//2
                t[i] += 1
            else:
                s[i] += abs(diff)//2
        else:
            t[i] += diff
    sums = sum(s)
    sumt = sum(t)
    remains = k - sums
    remaint = k - sumt
    if remains < 0 or remaint < 0:
        print('No')
        return
    if remains == 0 and remaint == 0:
        print('Yes')
        return
    if remains * 2 == remaint:
        print('Yes')
        return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
B = lma()
D = [B[i]-A[i] for i in range(n)]
tmp = 0

for d in D:
    if d>0:
        d//=2
    tmp+=d
f=False
if tmp>=0:
    f=True

yn(f)

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) #操作の回数はK回で確定

# b[j]に+1をa[j]に-1に変換する
Plus_Two=K
Minus_One=K


for i in range(N):
    D=B[i]-A[i]
    if D>0:
        Plus_Two-=(D+1)//2
        Minus_One-=D%2
    else:
        D=-D
        Minus_One-=D

if min(Plus_Two,Minus_One)>=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()))


K=sum(B)-sum(A) #操作の回数はK回で確定

# b[j]に+1をa[j]に-1に変換する
Plus_Two=K
Minus_One=K


for i in range(N):
    D=B[i]-A[i]
    if D>0:
        Plus_Two-=(D+1)//2
        Minus_One-=D%2
    else:
        D=-D
        Minus_One-=D

if min(Plus_Two,Minus_One)>=0 and Plus_Two*2-Minus_One==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    b = list(mi())
    K = sum(b) - sum(a)

    if sum(max(0, (b[i]-a[i]+1)//2) for i in range(N)) <= K:
        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()))
step = sum(B) - sum(A)
if step < 0:
    print('No')
    exit()

a_cnt = 0
b_cnt = 0

for a, b in zip(A, B):
    tmp = a - b
    if tmp > 0:
        b_cnt += tmp
    elif tmp < 0:
        tmp = abs(tmp)
        if tmp % 2 == 0:
            a_cnt += tmp // 2
        else:
            a_cnt += tmp // 2 + 1
            b_cnt += 1
if step >= 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()))

plus, minus = 0, 0
for i in range(N):
  if a[i]-b[i] >= 0:
    minus += a[i]-b[i]
  else:
    m = b[i]-a[i]
    plus += (m+1) // 2
    if m%2 == 1:
      minus += 1
    
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()))
ca = 0
cb = 0
for aa, bb in zip(a, b):
    if aa < bb:
        cb += (bb - aa)//2
    if bb < aa:
        ca += aa - bb
# print(ca, cb)
if cb >= ca:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))

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

if b >= a:
    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()))

total1 = 0
total2 = 0

for i in range(N):
    if a[i]>b[i]:
        total1 += a[i]-b[i]
    else:
        total2 += (b[i]-a[i])//2

if total1 <=total2:
    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=sum(b)-sum(a)
for i,j in zip(a,b):
  if i<j:cnt-=(j-i+1)//2
print(['No','Yes'][cnt>=0])

Submission status: Accepted

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

j = sum(b) - sum(a)
c = [0, 0]
for i in range(n):
    if a[i] > b[i]:
        c[0] += a[i] - b[i]
    if a[i] < b[i]:
        c[1] += -(-(b[i]-a[i])//2)

print("Yes" if max(c) <= j else "No")

Submission status: Accepted

Solution code:
n, *p = map(int, open(0).read().split())
s = sum(j - i - max(0, i - j) - max(0, j - i)%2 for i, j in zip(p, p[n:]))
print("Yes" if s >= 0 == s%2 else "No")

Submission status: Accepted

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

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

    if stock >= need:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
(n,),a,b=[[*map(int,i.split())]for i in open(0)]
print("YNeos"[sum(min(j-i,(j-i)//2) for i,j in zip(a,b))<0::2])

Submission status: Accepted

Solution code:
(n,),a,b=[[*map(int, i.split())]for i in open(0)]
print("YNeos"[sum(j - i if i > j else (j-i)//2 for i, j in zip(a,b))<0::2])

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    cnt = 0
    for x, y in zip(a, b):
        diff = x - y
        if diff < 0:
            cnt += abs(diff) // 2

    for x, y in zip(a, b):
        diff = x - y
        if diff > 0:
            cnt -= diff

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def division_with_round_up(x, y):
    return -(-x // y)


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    acnt = 0
    bcnt = 0

    for i in range(N):
        if A[i] == B[i]:
            continue
        elif A[i] > B[i]:
            bcnt += A[i] - B[i]
        else:
            acnt += division_with_round_up(B[i] - A[i], 2)
            bcnt += (B[i] - A[i]) % 2

    if acnt < bcnt:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()