Problem:


問題 A : Koto Distance

問題文

	Koto は言わずと知れた碁盤の目の街である．
	この街は東西方向に W メートル，南北方向に H メートルに伸びる長方形の領域によってできている．
	この街の西端から x メートル，南端から y メートルの点は (x,&thinsp; y)  と記される．
	ここの街に住む人は古くから伝わる独自の文化を重んじており，その一つにKoto距離という変わった距離尺度がある．
2つの点 (x_1, y_1)，(x_2, y_2) の Koto 距離は，min(|x_1 - x_2|,&thinsp; |y_1 - y_2|) によって定義される．

	最近この街全体に Wifi を使えるようにする計画が立ち上がった．
	現在の計画では，親機を N 個作ることになっている．
i 番目の親機は点 (x_i, &thinsp;y_i) に設置され，Koto距離が w_i 以下の領域に対して Wifi を提供する．

	親機を計画どおり建てた場合に，街の内部及び境界上に Wifi を提供できるかどうかを判定せよ．

	なお，Koto距離は一般に三角不等式を満たさないため，距離の公理を満たさないということはここだけの秘密である．

入力形式

入力は以下の形式で与えられる．

N W H
x_1 y_1 w_1
...
x_N y_N w_N

出力形式

街の内部および境界上に Wifi を提供できるなら “Yes” を，そうでない場合は “No” を出力せよ．

制約

1 ≤ N ≤ 10^5

1 ≤ W ≤ 10^5

1 ≤ H ≤ 10^5

0 ≤ x_i ≤ W

0 ≤ y_i ≤ H

1 ≤ w_i ≤ 10^5

同一座標に親機は複数存在しない

入出力例

入力例 1

3 9 9
2 2 2
5 5 2
8 8 2

出力例 1

Yes

２番目の親機が提供するWifiの範囲は以下の通りである．

入力例 2

2 7 7
2 2 1
6 6 1

出力例 2

No

入力例 3

3 10 20
5 10 5
2 10 1
8 10 1

出力例 3

Yes



Sample input:
3 9 9
2 2 2
5 5 2
8 8 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n, w, h = map(int, input().split())
xlst = [0] * (w + 2)
ylst = [0] * (h + 2)
for _ in range(n):
  x, y, width = map(int,input().split())
  xlst[max(0, x - width)] += 1
  ylst[max(0, y - width)] += 1
  xlst[min(w + 1, x + width + 1)] -= 1
  ylst[min(h + 1, y + width + 1)] -= 1

accx = list(accumulate(xlst))[:-1]
accy = list(accumulate(ylst))[:-1]
if 0 not in accx or 0 not in accy:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n, W, H = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(n)]

imos_h = [0] * (H + 2)
imos_w = [0] * (W + 2)

for x, y, w in X:
  imos_h[max(0, y - w)] += 1
  imos_h[min(W + 1, y + w + 1)] -= 1
  imos_w[max(0, x - w)] += 1
  imos_w[min(H + 1, x + w + 1)] -= 1
  
for h in range(H):
  imos_h[h + 1] += imos_h[h]
  
for w in range(W):
  imos_w[w + 1] += imos_w[w]

is_w = all(imos_w[w] >= 1 for w in range(W + 1))
is_h = all(imos_h[h] >= 1 for h in range(H + 1))

if h or w:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n, W, H = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(n)]

imos_h = [0] * (H + 2)
imos_w = [0] * (W + 2)

for x, y, w in X:
  imos_h[max(0, y - w)] += 1
  imos_h[min(H + 1, y + w + 1)] -= 1
  imos_w[max(0, x - w)] += 1
  imos_w[min(W + 1, x + w + 1)] -= 1
  
for h in range(H):
  imos_h[h + 1] += imos_h[h]
  
for w in range(W):
  imos_w[w + 1] += imos_w[w]

is_w = all(imos_w[w] >= 1 for w in range(W + 1))
is_h = all(imos_h[h] >= 1 for h in range(H + 1))

if is_h or is_w:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n, W, H = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(n)]

imos_h = [0] * (H + 2)
imos_w = [0] * (W + 2)

for x, y, w in X:
  imos_h[max(0, y - w)] += 1
  imos_h[min(H + 1, y + w + 1)] -= 1
  imos_w[max(0, x - w)] += 1
  imos_w[min(W + 1, x + w + 1)] -= 1
  
for h in range(H):
  imos_h[h + 1] += imos_h[h]
  
for w in range(W):
  imos_w[w + 1] += imos_w[w]

is_w = all(imos_w[w] >= 1 for w in range(W))
is_h = all(imos_h[h] >= 1 for h in range(H))

if is_h or is_w:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n, W, H = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(n)]

imos_h = [0] * (H + 2)
imos_w = [0] * (W + 2)

for x, y, w in X:
  imos_h[max(0, y - w)] += 1
  imos_h[min(H + 1, y + w)] -= 1
  imos_w[max(0, x - w)] += 1
  imos_w[min(W + 1, x + w)] -= 1
  
for h in range(H):
  imos_h[h + 1] += imos_h[h]
  
for w in range(W):
  imos_w[w + 1] += imos_w[w]

is_w = all(imos_w[w] >= 1 for w in range(W + 1))
is_h = all(imos_h[h] >= 1 for h in range(H + 1))

if is_h or is_w:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
def read():
  return list(map(int,input().split()))

while 1:
  try:
    n,w,h=read()
    bases=[(0,0,0)]*n
    for i in range(n):
      bases[i]=read()
  except: break
  
  res1=True
  ls,rs=zip(*sorted([(x-w,x+w) for x,y,w in bases],key=lambda lr:lr[0]))
  x=0
  for l,r in zip(ls,rs):
    res1&=l<=x
    x=max(x,r)
  res1&=w<=x
  
  res2=True
  ls,rs=zip(*sorted([(y-w,y+w) for x,y,w in bases],key=lambda lr:lr[0]))
  x=0
  for l,r in zip(ls,rs):
    res2&=l<=x
    x=max(x,r)
  res2&=h<=x
  
  print("Yes" if res1 and res2 else "No")

Submission status: Wrong Answer

Solution code:
import sys

in_txt=sys.stdin.read().splitlines()

n,w,h = map(int, in_txt[0].split())

wifi_list=[]
x_list = [False for i in range(w+1)]
y_list = [False for i in range(h+1)]


for i in in_txt[1:]:

    xi,yi,wi = map(int, i.split())
    xs=xi-wi if xi-wi>=0 else 0
    xe=xi+wi if xi+wi<=w else w
    ys=yi-wi if yi-wi>=0 else 0
    ye=yi+wi if yi+wi<=h else h
    x_list[xs:xe+1]=[True]
    y_list[ys:ye+1]=[True]

if False in x_list or False in y_list:
    print 'No'
else:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
import sys

in_txt=sys.stdin.read().splitlines()

n,w,h = map(int, in_txt[0].split())

wifi_list=[]
x_list = [False for i in range(w+1)]
y_list = [False for i in range(h+1)]


for i in in_txt[1:]:
   
    xi,yi,wi = map(int, i.split())
    xs=xi-wi if xi-wi>=0 else 0
    xe=xi+wi if xi+wi<=w else w
    ys=yi-wi if yi-wi>=0 else 0
    ye=yi+wi if yi+wi<=h else h
    x_list[xs:xe+1]=[True for j in range(xe-xs)]
    y_list[ys:ye+1]=[True for j in range(ye-ys)]

print x_list
print y_list
if False in x_list or False in y_list:
    print 'No'
else:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
import sys

in_txt=sys.stdin.read().splitlines()

n,w,h = map(int, in_txt[0].split())

wifi_list=[]
x_list = [False for i in range(w+1)]
y_list = [False for i in range(h+1)]


for i in in_txt[1:]:
   
    xi,yi,wi = map(int, i.split())
    xs=xi-wi if xi-wi>=0 else 0
    xe=xi+wi if xi+wi<=w else w
    ys=yi-wi if yi-wi>=0 else 0
    ye=yi+wi if yi+wi<=h else h
    x_list[xs:xe+1]=[True for j in range(xe-xs)]
    y_list[ys:ye+1]=[True for j in range(ye-ys)]


if False in x_list or False in y_list:
    print 'No'
else:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
import sys

in_txt=sys.stdin.read().splitlines()

n,w,h = map(int, in_txt[0].split())

wifi_list=[]

prev_area = [[False for i in range(w+1)] for j in range(h+1)]
area = [[False for i in range(w+1)] for j in range(h+1)]

for i in in_txt[1:]:

    xi,yi,wi = map(int, i.split())
    xs=xi-wi if xi-wi>=0 else 0
    xe=xi+wi if xi+wi<=w else w
    ys=yi-wi if yi-wi>=0 else 0
    ye=yi+wi if yi+wi<=h else h

    area = [[True if prev_area or(i>=xs and i<=xe) or (j>=ys and j<=ye) else False for i in range(w+1)]for j in range(h+1)]
    prev_area=area

flag=False
for i in area:
    if False in i:
        flag=True
        break

if flag:
    print 'No'
else:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
N,W,H = map(int,raw_input().split())
X,Y = [0]*(W+1),[0]*(H+1)
for loop in xrange(N):
    x,y,w = map(int,raw_input().split())
    X[max(0,x-w)] += 1
    X[min(W,x+w)] += -1
    Y[max(0,y-w)] += 1
    Y[min(H,y+w)] += -1
for i in xrange(1,W+1): X[i] += X[i-1]
for i in xrange(1,H+1): Y[i] += Y[i-1]
print "Yes" if 0 not in X[1:-1] or 0 not in Y[1:-1] else "No"

Submission status: Wrong Answer

Solution code:
N,W,H = map(int,raw_input().split())
X,Y = [0]*(W+1),[0]*(H+1)
for loop in xrange(N):
    x,y,w = map(int,raw_input().split())
    X[max(0,x-w)] += 1
    X[min(W,x+w)] += -1
    Y[max(0,y-w)] += 1
    Y[min(H,y+w)] += -1
for i in xrange(1,W+1): X[i] += X[i-1]
for i in xrange(1,H+1): Y[i] += Y[i-1]
print "Yes" if 0 not in X or 0 not in Y else "No"

Submission status: Wrong Answer

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

import sys

N, W, H = map(int, raw_input().split())

spots = []
for i in range(N):
	x, y, w = map(int, raw_input().split())
	spots.append([w, x, y])

spots = sorted(spots)

rows = [False] * H
cols = [False] * W

for w, x, y in spots:
	for i in range(max(0, x-w), min(W, x+w)):
		cols[i] = True
	for i in range(max(0, y-w), min(H, y+w)):
		rows[i] = True

print rows
print cols
row = reduce(lambda x, y: x and y, rows)
col = reduce(lambda x, y: x and y, cols)

if row and col:
	print 'Yes'
else:
	print 'No'

Submission status: Wrong Answer

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

import sys

N, W, H = map(int, raw_input().split())

spots = []
for i in range(N):
	x, y, w = map(int, raw_input().split())
	spots.append([w, x, y])

spots = sorted(spots)

rows = [False] * H
cols = [False] * W

for w, x, y in spots:
	for i in range(max(0, x-w), min(W, x+w)):
		cols[i] = True
	for i in range(max(0, y-w), min(H, y+w)):
		rows[i] = True

row = reduce(lambda x, y: x and y, rows)
col = reduce(lambda x, y: x and y, cols)

if row and col:
	print 'Yes'
else:
	print 'No'

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#Problem Name: Koto Distance
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

class point:
    def __init__(self,x,y):
        self.x, self.y = x,y
        self.judge = False

    def dist(self,other):
        return min(abs(self.x-other.x), abs(self.y-other.y))

town = [point(x,y) for x in range(10) for y in range(10)]

while True:
    try:
        N,W,H = map(int,raw_input().split(' '))
        for t in town:
            if t.dist(point(N,W)) <= H:
                t.judge = True
    except:
        break

if all([t.judge for t in town]):
    print 'Yes'
else:
    print 'No'

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#Problem Name: Koto Distance
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

class point:
    def __init__(self,x,y):
        self.x, self.y = x,y
        self.judge = False

    def dist(self,other):
        return min(abs(self.x-other.x), abs(self.y-other.y))

N,W,H = map(int,raw_input().split(' '))
town = [point(x,y) for x in range(W) for y in range(H)]

for i in range(N):
    x,y,w = map(int,raw_input().split(' '))
    for t in town:
        if t.dist(point(x,y)) <= w:
            t.judge = True
    
if all([t.judge for t in town]):
    print 'Yes'
else:
    print 'No'

Submission status: Wrong Answer

Solution code:
import fileinput
hoge = fileinput.input()
tmp = hoge.next()
N,W,H = map(int, tmp.strip().split(" "))
wifis = []
for line in hoge:
    wifis.append(map(int, line.strip().split(" ")))

xw = set([])
yw = set([])

for x,y,w in wifis:
    xw.update(set([i for i in xrange(x - w, x + w + 1) if 0 <= i <= W]))
    yw.update(set([i for i in xrange(y - w, y + w + 1) if 0 <= i <= H]))

if len(yw) == W + 1 or len(xw) == H + 1:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
import fileinput
hoge = fileinput.input()
tmp = hoge.next()
N,W,H = map(int, tmp.strip().split(" "))
wifis = []
for line in hoge:
    wifis.append(map(int, line.strip().split(" ")))

xw = set([])
yw = set([])

for x,y,w in wifis:
    xw.update(set([i for i in xrange(x - w, x + w + 1) if 0 <= i <= W]))
    yw.update(set([i for i in xrange(y - w, y + w + 1) if 0 <= i <= H]))
if len(yw) == H + 1 or len(xw) == W + 1:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
N,W,H=map(int,raw_input().split())
W+=1
H+=1
wa=[0]*(W+1)
ha=[0]*(H+1)
for _ in xrange(N):
    x,y,w=map(int,raw_input().split())
    wa[x-w]+=1
    if x+w+1<=W: wa[x+w+1]-=1
    ha[y-w]+=1
    if y+w+1<=H: ha[y+w+1]-=1
for i in xrange(W): wa[i+1]+=wa[i]
for i in xrange(H): ha[i+1]+=ha[i]
if 0 in wa[:W] and 0 in ha[:H]:
    print "No"
else:
    print "Yes"

Submission status: Wrong Answer

Solution code:
N,W,H=map(int,raw_input().split())
W+=1
H+=1
wa=[0]*(W+1)
ha=[0]*(H+1)
for _ in xrange(N):
    x,y,w=map(int,raw_input().split())
    wa[max(x-w,0)]+=1
    if x+w+1<=W: wa[x+w+1]-=1
    ha[max(y-w,0)]+=1
    if y+w+1<=H: ha[y+w+1]-=1
for i in xrange(W): wa[i+1]+=wa[i]
for i in xrange(H): ha[i+1]+=ha[i]
if 0 in wa[:W] and 0 in ha[:H]:
    print "No"
else:
    print "Yes"

Submission status: Wrong Answer

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

wifi = []
for _ in range(N):
    w = [int(x) for x in input().split()]
    wifi.append(w)


for x in range(W):
    for w_x, w_y, w_r in wifi:
        if w_x - w_r <= x < w_x + w_r:
            break
    else:
        break
else:
    print('Yes')
    exit()

for y in range(W):
    for w_x, w_y, w_r in wifi:
        if w_y - w_r <= y < w_y + w_r:
            break
    else:
        break
else:
    print('Yes')
    exit()

print('No')

Submission status: Wrong Answer

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

wifi = []
for _ in range(N):
    w = [int(x) for x in input().split()]
    wifi.append(w)


for x in range(W):
    for w_x, w_y, w_r in wifi:
        if w_x - w_r <= x < w_x + w_r:
            break
    else:
        break
else:
    print('Yes')
    exit()


for y in range(W):
    for w_x, w_y, w_r in wifi:
        if w_y - w_r <= y < w_y + w_r:
            break
    else:
        break
else:
    print('Yes')
    exit()


print('No')

Submission status: Wrong Answer

Solution code:
n,w,h = map(int,input().split())
Yoko = [0] * w
Tate = [0] * h
for i in range(n):
    x,y,r = map(int,input().split())
    for j in range(x - 2,x + 2):
        if j < w:
            Yoko[j] += 1
        if j < h:
            Tate[j] += 1
    print(Yoko)
    print(Tate)
if Yoko.count(0) > 0 or Tate.count(0) > 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,w,h = map(int,input().split())
Yoko = [0] * w
Tate = [0] * h
for i in range(n):
    x,y,r = map(int,input().split())
    for j in range(x - 2,x + 2):
        if j < w:
            Yoko[j] += 1
        if j < h:
            Tate[j] += 1
if Yoko.count(0) > 0 or Tate.count(0) > 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,w,h = map(int,input().split())
Yoko = [0] * w
Tate = [0] * h
for i in range(n):
    x,y,r = map(int,input().split())
    for j in range(x - r,x + r):
        if j < w:
            Yoko[j] += 1
    for j in range(y- r,y + r):
        if j < h:
            Tate[j] += 1

if Yoko.count(0) == 0 or Tate.count(0) == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)

if Yoko[0][0] > 0 and Tate[0][0]:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] < Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
                print(Yoko_han)
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[j][0] < Tate_han[1] and Tate_han[1] < Tate[j][1]:
                Tate_han[1] = Tate[j][1]
                print(Tate_han)
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                print("No")
                break

Submission status: Wrong Answer

Solution code:
import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)

if Yoko[0][0] > 0 and Tate[0][0]:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] < Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[j][0] < Tate_han[1] and Tate_han[1] < Tate[j][1]:
                Tate_han[1] = Tate[j][1]
 
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                print("No")
                break

Submission status: Wrong Answer

Solution code:
import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)
if Yoko[0][0] > 0 and Tate[0][0]:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] <= Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
           
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[j][0] < Tate_han[1] and Tate_han[1] < Tate[j][1]:
                Tate_han[1] = Tate[j][1]

 
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                print("No")
                break

Submission status: Wrong Answer

Solution code:
import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)

if Yoko[0][0] > 0 and Tate[0][0]:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] <= Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
           
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[k][0] <= Tate_han[1] and Tate_han[1] < Tate[k][1]:
                Tate_han[1] = Tate[k][1]
 
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[k][0]:
                print("No")
                break

Submission status: Wrong Answer

Solution code:
import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)

if Yoko[0][0] > 0 and Tate[0][0]:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] <= Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
           
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[k][0] <= Tate_han[1] and Tate_han[1] < Tate[k][1]:
                Tate_han[1] = Tate[k][1]
 
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[k][0]:
                print("No")
                sys.exit()
print("No")

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,w,h = LI()
        a = [LI() for _ in range(n)]
        b = []
        c = []
        for x,y,w in a:
            b.append((x-w,x+w))
            c.append((y-w,y+w))
        b.sort()
        c.sort()
        f = False
        mi = b[0][0]
        ma = b[0][1]
        for l,r in b[1:]:
            if l > ma:
                break
            ma = max(r,ma)
        if mi <= 0 and ma >= w:
            f = True
        mi = c[0][0]
        ma = c[0][1]
        for l,r in c[1:]:
            if l > ma:
                break
            ma = max(r,ma)
        if mi <= 0 and ma >= h:
            f = True

        if f:
            rr.append('Yes')
        else:
            rr.append('No')
        break

    return '\n'.join(map(str, rr))


print(main())

Submission status: Time Limit Exceeded

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

import sys

N, W, H = map(int, raw_input().split())

spots = []
for i in range(N):
	x, y, w = map(int, raw_input().split())
	spots.append([w, x, y])

spots = sorted(spots)

rows = [False] * H
cols = [False] * W

for w, x, y in spots:
	for i in range(max(0, x-w), min(W, x+w)):
		cols[i] = True
	for i in range(max(0, y-w), min(H, y+w)):
		rows[i] = True

row = reduce(lambda x, y: x and y, rows)
col = reduce(lambda x, y: x and y, cols)

if row or col:
	print 'Yes'
else:
	print 'No'

Submission status: Time Limit Exceeded

Solution code:
import fileinput
hoge = fileinput.input()
tmp = hoge.next()
N,W,H = map(int, tmp.strip().split(" "))
wifis = []
for line in hoge:
    wifis.append(map(int, line.strip().split(" ")))

xw = set([])
yw = set([])

for x,y,w in wifis:
    #print x,y,[i for i in xrange(x - w, x + w + 1) if 0 <= i <= W]
    xw.update(set([i for i in xrange(x - w, x + w) if 0 <= i < W]))
    yw.update(set([i for i in xrange(y - w, y + w) if 0 <= i < H]))
if len(yw) == H or len(xw) == W:
    print "Yes"
else:
    print "No"

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
map_y = [False] * H

for _ in range(N):
    x, y, r = [int(x) for x in input().split()]

    for a in [b for b in range(x - r, x + r) if 0 <= b < W]:
        map_x[a] = True

    for a in [b for b in range(y - r, y + r) if 0 <= b < H]:
        map_y[a] = True

ans = False
for x in map_x:
    if not x:
        break
else:
    ans = True

for x in map_y:
    if not x:
        break
else:
    ans = True

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

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

for _ in range(N):
    x, y, r = [int(x) for x in input().split()]

    for a in [b for b in range(x - r, x + r) if 0 <= b < W]:
        if not map_x[a]:
            map_x[a] = True
            count_x += 1

    if count_x >= W:
        break

    for a in [b for b in range(y - r, y + r) if 0 <= b < H]:
        if not map_y[a]:
            map_y[a] = True
            count_y += 1

    if count_y >= H:
        break

print('Yes' if count_x >= W or count_y >= H else 'No')

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

for _ in range(N):
    x, y, r = [int(x) for x in input().split()]

    for a in [b for b in range(x - r, x + r) if 0 <= b < W and not map_x[b]]:
        map_x[a] = True
        count_x += 1

    if count_x >= W:
        break

    for a in [b for b in range(y - r, y + r) if 0 <= b < H and not map_y[b]]:
        map_y[a] = True
        count_y += 1

    if count_y >= H:
        break

print('Yes' if count_x >= W or count_y >= H else 'No')

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

wifi = []
for _ in range(N):
    w = [int(x) for x in input().split()]
    wifi.append(w)


def check_x(l):
    for x, _, r in wifi:
        if x - r <= l < x + r:
            return True

    return False


def check_y(l):
    for _, y, r in wifi:
        if y - r <= l < y + r:
            return True

    return False


ans_x = True
for x in range(W):
    if not check_x(x):
        ans_x = False
        break

if not ans_x:
    for y in range(H):
        if not check_y(y):
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

wifi = []
for _ in range(N):
    x, y, w = [int(x) for x in input().split()]
    wifi.append((x - w, x + w, y - w, y + w))


def check_x(l):
    for x1, x2, _, _ in wifi:
        if x1 <= l < x2:
            return True
    return False


def check_y(l):
    for _, _, y1, y2 in wifi:
        if y1 <= l < y2:
            return True
    return False


ans_x = True
for x in range(W):
    if not check_x(x):
        ans_x = False
        break

if not ans_x:
    for y in range(H):
        if not check_y(y):
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

wifi_x = []
wifi_y = []
for _ in range(N):
    x, y, w = [int(x) for x in input().split()]
    wifi_x.append((x - w, x + w))
    wifi_y.append((y - w, y + w))


def check_x(l):
    for x1, x2 in wifi_x:
        if x1 <= l < x2:
            return True
    return False


def check_y(l):
    for y1, y2 in wifi_y:
        if y1 <= l < y2:
            return True
    return False


ans_x = True
for x in range(W):
    if not check_x(x):
        ans_x = False
        break

if not ans_x:
    for y in range(H):
        if not check_y(y):
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N, W, H = [int(x) for x in input().split()]

map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0

wifi_x = []
wifi_y = []
for _ in range(N):
    x, y, w = [int(x) for x in input().split()]
    wifi_x.append((x - w, x + w))
    wifi_y.append((y - w, y + w))
wifi_x.sort(key=lambda a: a[1], reverse=True)
wifi_y.sort(key=lambda a: a[1], reverse=True)


def check_wifi(wifi, l):
    for x1, x2 in wifi:
        if x1 <= l < x2:
            return x2
    return None


ans_x = True
b = 0
for x in range(W):
    if x < b:
        continue

    b = check_wifi(wifi_x, x)
    if not b:
        ans_x = False
        break

if not ans_x:
    b = 0
    for y in range(H):
        if y < b:
            continue

        b = check_wifi(wifi_y, y)
        if not b:
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n,w,h = map(int,input().split())
Yoko = [0] * w
Tate = [0] * h
for i in range(n):
    x,y,r = map(int,input().split())
    for j in range(x - r,x + r):
        if 0 <= j < w:
            Yoko[j] += 1
    for j in range(y- r,y + r):
        if 0 <= j < h:
            Tate[j] += 1
if Yoko.count(0) == 0 or Tate.count(0) == 0:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
n,w,h = map(int,input().split())
Yoko = [0] * w
Tate = [0] * h
for i in range(n):
    x,y,r = map(int,input().split())
    for j in range(x - r,x + r):
        if 0 <= j < w:
            Yoko[j] += 1
    for j in range(y- r,y + r):
        if 0 <= j < h:
            Tate[j] += 1
    if Yoko.count(0) == 0 or Tate.count(0) == 0:
        break
if Yoko.count(0) == 0 or Tate.count(0) == 0:
    print("Yes")
else:
    print("No")

Submission status: Memory Limit Exceeded

Solution code:
import sys

in_txt=sys.stdin.read().splitlines()

n,w,h = map(int, in_txt[0].split())

wifi_list=[]

prev_area = [[False for i in range(w+1)] for j in range(h+1)]
area = [[False for i in range(w+1)] for j in range(h+1)]

for i in in_txt[1:]:

    xi,yi,wi = map(int, i.split())
    xs=xi-wi if xi-wi>=0 else 0
    xe=xi+wi if xi+wi<=w else w
    ys=yi-wi if yi-wi>=0 else 0
    ye=yi+wi if yi+wi<=h else h
    area = [[True if prev_area[k][j] or(j>=xs and j<=xe) or (k>=ys and k<=ye) else False for j in range(w+1)]for
 k in range(h+1)]
    prev_area=area

flag=False
for i in area:
    if False in i:
        flag=True
        break
if flag:
    print 'No'
else:
    print 'Yes'

Submission status: Accepted

Solution code:
from itertools import accumulate
n, w, h = map(int, input().split())
xlst = [0] * (w + 1)
ylst = [0] * (h + 1)
for _ in range(n):
  x, y, width = map(int,input().split())
  xlst[max(0, x - width)] += 1
  ylst[max(0, y - width)] += 1
  xlst[min(w, x + width)] -= 1
  ylst[min(h, y + width)] -= 1

accx = list(accumulate(xlst))[:-1]
accy = list(accumulate(ylst))[:-1]
if 0 not in accx or 0 not in accy:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n, W, H = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(n)]

imos_h = [0] * (H + 2)
imos_w = [0] * (W + 2)

for x, y, w in X:
  imos_h[max(0, y - w)] += 1
  imos_h[min(H + 1, y + w)] -= 1
  imos_w[max(0, x - w)] += 1
  imos_w[min(W + 1, x + w)] -= 1
  
for h in range(H):
  imos_h[h + 1] += imos_h[h]
  
for w in range(W):
  imos_w[w + 1] += imos_w[w]

is_w = all(imos_w[w] >= 1 for w in range(W))
is_h = all(imos_h[h] >= 1 for h in range(H))

if is_h or is_w:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def read():
  return list(map(int,input().split()))

while 1:
  try:
    n,w,h=read()
    bases=[(0,0,0)]*n
    for i in range(n):
      bases[i]=read()
  except: break
  
  res1=True
  ls,rs=zip(*sorted([(x-w,x+w) for x,y,w in bases],key=lambda lr:lr[0]))
  x=0
  for l,r in zip(ls,rs):
    res1&=l<=x
    x=max(x,r)
  res1&=w<=x
  
  res2=True
  ls,rs=zip(*sorted([(y-w,y+w) for x,y,w in bases],key=lambda lr:lr[0]))
  x=0
  for l,r in zip(ls,rs):
    res2&=l<=x
    x=max(x,r)
  res2&=h<=x
  
  print("Yes" if res1 or res2 else "No")