n, m, s = map(int, input().split())
lista = []
for i in range(m):
a, b = map(int, input().split())
lista.append([a, b])
lista = sorted(lista)
listb = []
for i in range(len(lista)):
if lista[i][0]<=s and lista[i][1]>=s:
listb.append(lista[i][0])
listb.append(lista[i][1])
cos = i
break
listc = listb
x1, x2 = 0, 0
for i in range(cos-1, -1, -1):
if listc[0]-1==lista[i][1]:
listc[0]=lista[i][0]
x1 = listc[0]-1
if listc[0]==1:
x1= -100000000000000000
for i in range(cos+1, m):
if listc[1]+1==lista[i][0]:
listc[1]=lista[i][1]
x2 = listc[1]+1
if listc[1]==n:
x2 = 100000000000000000000
if s-x1 < x2-s:
print(x1)
elif x2-s < s-x1:
print(x2)
else:
print(x1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | n, m, s = map(int, input().split()) lista = [] for i in range(m): a, b = map(int, input().split()) lista.append([a, b]) lista = sorted(lista) listb = [] for i in range(len(lista)): if lista[i][0]<=s and lista[i][1]>=s: listb.append(lista[i][0]) listb.append(lista[i][1]) cos = i break listc = listb x1, x2 = 0, 0 for i in range(cos-1, -1, -1): if listc[0]-1==lista[i][1]: listc[0]=lista[i][0] x1 = listc[0]-1 if listc[0]==1: x1= -100000000000000000 for i in range(cos+1, m): if listc[1]+1==lista[i][0]: listc[1]=lista[i][1] x2 = listc[1]+1 if listc[1]==n: x2 = 100000000000000000000 if s-x1 < x2-s: print(x1) elif x2-s < s-x1: print(x2) else: print(x1) |
English