0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ABC127 C - Prison に怒られた気がした

Posted at

abc127_1.png
abc127_2.png
abc127_3.png
abc127_4.png

踏む踏む。
つまり L1 - R1 ~ LM - RM 間で共通項が何個あるか聞かれている気がした。

サクッと書いて WA.

Prison.py
N,M = map(int,input().split())
L = []
R = []
 
for _ in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
 
st = max(L)
ed = min(R)
 
print(ed-st+1)

ん~、何で??

例えば L1, R1 がクソ大きい値だったとする。
L2,R2 がクソ小さい値だった場合。
冒頭の記述だとマイナスの場合が出てこないか?

Prison.py
N,M = map(int,input().split())
L = []
R = []
 
for _ in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
 
st = max(L)
ed = min(R)
 
print(max(ed-st+1,0))# マイナスが出た場合、0 を最大値として取るように修正

ちゃんとエッジケースは考えなよ、イージーだね。。。って怒られた気がした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?