prompt
string
response
string
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x = map(int, input().split()) start, end = 0, 1000 for _ in range(n): a, b = map(int, input().split()) if a > b: a, b = b, a if a > start: start = a if b < end: end = b if start > end: print(-1) else: if x >= start and x <= end: print(0) elif x < start: ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import os import sys debug = True if debug and os.path.exists("input.in"): input = open("input.in", "r").readline else: debug = False input = sys.stdin.readline def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return (list...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class Main14B { static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int xo=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x = map(int,input().split()) c = [[0,10000000]] for i in range(n): a,b = map(int,input().split()) if(a<=b): if(c[-1][-1]>=a and c[-1][0]<=b): c[-1][0] = max(c[-1][0],a) c[-1][-1] = min(c[-1][-1],b) else: print(-1) exit() else: b,a = ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; public class photography { // http://codeforces.com/problemset/problem/14/B public static class Pair{ int L; int R; Pair(int l, int ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int absolute(int x) { if (x > 0) return x; else return -x; } int min(int a, int b) { if (a < b) return a; else return b; } int max(int a, int b) { if (a > b) return a; else return b; } int main() { int i, x0, n, l, r; vector<int> a, b...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> int main() { int a[1000], b[10000], max1, i, j, k, l, m, n, c, cnt, min1, d, r, s; while (scanf("%d %d", &m, &n) == 2) { max1 = 0; min1 = s = r = 88899; for (i = 1; i <= m; i++) { scanf("%d%d", &a[i], &b[i]); l = (a[i] < b[i] ? a[i] : b[i]); k = (a[i] > b[i] ? ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x= map(int,raw_input().split()) s =0 e = 1000 for _ in xrange(n): a,b = sorted(map(int,raw_input().split())) s = max(s,a) e = min(e,b) #print s,e if s>e: print -1 else: if x>=s and x<=e: print 0 elif x<s: print s-x else: print x-e
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int pos, n; cin >> n >> pos; int x, y; cin >> x >> y; int a = min(x, y); int b = max(x, y); for (int i = 0; i < n - 1; ++i) { cin >> x >> y; a = max(a, min(x, y)); b = min(b, max(x, ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int m[1007]; int main() { int n, x, s[10007], a, b; scanf("%d %d", &n, &x); for (int i = 1; i <= n; ++i) { scanf("%d %d", &a, &b); if (a > b) swap(a, b); for (int j = a; j <= b; ++j) { m[j]++; } } int mi = 1007; for (int i = 1; i <= 1001; +...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int a[100][100]; int main() { int n, x, i, j, left = 0, right = 99999, t = 0, k; cin >> n >> x; for (k = 0; k < n; k++) { cin >> i >> j; if (i > j) swap(i, j); left = max(left, i); right = min(right, j); if (left > right) t = 1; } if (t == 1) ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import math class Interval: def __init__(self, a=0, b=0): self.a = a self.b = b pass (n, x) = raw_input().split() n = int(n) x = int(x) resultInterval = Interval(-1, 100000) for i in range(n): interval = Interval() (interval.a, interval.b) = raw_input().split() interval.a = int(i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.Scanner; public class B { public static void main(String[] args) { new B().run(); } private void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int px = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { int x = sc.nextInt(...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
# 14.B import sys MINX = 0 MAXX = 1000 if len (sys.argv) > 1: sys.stdin = open (sys.argv[1], 'r') def check (x): if x < MINX or x > MAXX: return False for i in xrange (0, n): if (x < a[i]) or (x > b[i]): return False return True n, x0 = map (int, sys.stdin.readline().split()) a = [0] * n b = [0] * n for ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; typedef struct track_range { int small; int big; } TR; int max(int a, int b); int min(int a, int b); int main() { TR cur = {0, 0}, alr = {0, 0}; int men_num = 0; int org = 0; int i = 0; cin >> men_num >> org; for (i = 0; i < men_num; i++) { cin >> cur.sm...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int N = nextInt(); int me = nextInt(); int low = -10000; int high = +10000; for(int i = 0; i < N; i++){ i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
//package contest_14; import java.util.Scanner; public class B_YoungPhotgprapher { public static void main(String[] args) { Scanner sanat = new Scanner(System.in); int n = sanat.nextInt(); int x0 = sanat.nextInt(); int []x = new int[n+1]; int []y = new int[n+1]; int...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = map(int, input().split()) has = set([x for x in range(1, 1001)]) for _ in range(n): a, b = map(int, input().split()) a, b = min(a, b), max(a, b) has2 = set([x for x in range(a, b+1)]) has = has.intersection(has2) if len(has) == 0: print(-1) elif x0 in has: print(0) else: c = abs(m...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { long m = -1000, A, B, i, j, n, aux, x, a[1002] = {}, b[100], mi = 1000000, r = 1000000; scanf("%ld %ld", &n, &x); for (i = 0; i < n; i++) { scanf("%ld %ld", &A, &B); if (A > B) { aux = A; A = B; B = aux; } for (j =...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; public class YoungPhotographer { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); String s = r.readLine(); String[] sp = s.split(" "); int n = new Integer(sp[0]); int x ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.LinkedList; import java.util.List; /** * Created by James on 1/29/2015. */ public class Driver { public static void main(String [] args) throws IOException { BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new Pr...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.BufferedInputStream; import java.util.Scanner; /** * Created by jizhe on 2016/1/7. */ public class YoungPhotographer { public static void main(String[] args) { Scanner in = new Scanner(new BufferedInputStream(System.in)); int N = in.nextInt(); int x0 = in.nextInt(); ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a, b, m = 0, M = 1001, z; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a >> b; if (a > b) { int temp = a; a = b; b = temp; } if (b < M) { M = b; } if (a > m) { m = a; } } if (x...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x0 = [int(i) for i in input().split()] l = [] for i in range(n): list = [int(i) for i in input().split()] list.sort() l.append(list) a = l[0][0] for i in l: if i[0] > a: a = i[0] b = l[0][1] for i in l: if i[1] < b: b = i[1] if b < a: print(-1) elif x0 >= a and b >= x0: p...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> int n, x, i, t, tt, ttt, tttt, l = -2000, r = 2000; int main(void) { scanf("%d %d", &n, &x); for (i = 0; i < n; ++i) { scanf("%d %d", &t, &tt); ttt = (t > tt) ? tt : t; tttt = (t > tt) ? t : tt; t = (l > ttt) ? l : ttt; tt = (r > tttt) ? tttt : r; if (!((t <= tt) && ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { if (a > b) { return b; } else { return a; } } int max(int a, int b) { if (a > b) { return a; } else { return b; } } int main() { int n, x0; int a, b; int d, f; cin >> n >> x0 >> a >> b; if (a > b) { d = b; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; string tostr(long long x) { stringstream ss; ss << x; return ss.str(); } long long toint(const string &s) { stringstream ss; ss << s; long long x; ss >> x; return x; } int main() { int n, x, l, r, t1, t2; scanf("%d", &n); ; scanf("%d", &x); ; sca...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class B { private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = map(int, raw_input().split()) coords = [ sorted(map(int, raw_input().split())) for i in xrange(n) ] ans = 7777 for i in xrange(1000): ok = True for (l, r) in coords: if i < l or i > r: ok = False break else: ans = min(ans, abs(i - x0)) print ans if ans != 777...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import math (n, x) = map(int, raw_input().split()) (resultA, resultB) = (0, 1000) for i in range(n): (a, b) = map(int, raw_input().split()) if a > b: (a, b) = (b, a) (resultA, resultB) = (max(resultA, a), min(resultB, b)) if resultA <= x <= resultB: result = 0 elif resultA <= resul...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; public class apr1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x0 = sc.nextInt(); int min = 0; int max = 1000; for(int i=0;i<n;i++) { int a = sc.nextInt()...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x = map(int, input().split()) p = 0 q = 1001 for _ in range(n): a,b = map(int, input().split()) if a>b: t = a a = b b = t p = max(p,a) q = min(q,b) #print(p,q) if p<=q: if x<p: print(p-x) elif x>q: print(x-q) else: print('0') else:...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a[100], b[100], low = 500000, high = 0, test, temp, ans[10000], z = 0, flag = 1, mini = 999999; cin >> n >> x; test = x; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] > b[i]) { temp = a[i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import bisect as bi n,x=map(int,input().split()) l=[] h=[] ans=0 for i in range(n): a,b=map(int,input().split()) if a>b: l.append(b) h.append(a) else: l.append(a) h.append(b) l.sort() h.sort() if l[n-1]>h[0]: print(-1) else: m=bi.bisect(l,x) o=bi.bisect(h,x) i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> int n, x, i, l = -2000, r = 2000, t, tt, ttt, tttt; int main(void) { scanf("%d %d", &n, &x); for (i = 0; i < n; ++i) { scanf("%d %d", &t, &tt); ttt = (t > tt) ? tt : t; tttt = (t > tt) ? t : tt; t = (l > ttt) ? l : ttt; tt = (r > tttt) ? tttt : r; if (!((t <= tt) && ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x0; cin >> n >> x0; int x = x0; int a[n][2]; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; int c = 0, d = 0; for (int i = 0; i < n; i++) { if (min(a[i][0], a[i][1]) > x) { x = min(a[i][0], a[i][1]); c++; } else ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; public class YoungPhotographer { public static void main(String args[]) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int x = s.nextInt(); int a[] = new int[1002]; for (int i = 0; i < n; i++) { int c = s.nextInt(); ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.fill; import static java.util.Arrays.binarySearch; import static java.util.Arrays.sort; public class Main { public static void main(String[] args) throws IOException { new Thread(null, new Runnable() { public voi...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.*; public class j { public static void main(String aa[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); int i=0,n=0,k=0,j=0,p=0,m=0,x=-100000000,y=-100000000; String s; s=b.readLine(); StringTokenizer c=new StringTokenizer(s); n=Integer.pars...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
# -*- coding: UTF-8 -*- # from itertools import * # from collections import defaultdict # def gcd(a,b): # while b > 0: a,b = b, a%b # return a # def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"): # return ((num == 0) and "0" ) or ( baseN(num // b, b).lstrip("0") + numerals[num % b]) def ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x0 = map(int,raw_input().split()) ca,cb = 0,1000 for i in range(n): t = map(int,raw_input().split()) a = min(t) b = max(t) if a>cb: print -1 exit(0) if a<=cb and a >= ca: xa = a else: xa = ca if b < ca: print -1 exit(0) if b<=cb and b>=...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.lang.*; import java.io.*; public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int l = Integer.MIN_VALUE; int m = Integer.MAX_VALUE; int res...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.*; import java.math.*; public class YoungPhotoGrapher { static Stack <Character> stack=new Stack<Character>(); public static void main(String args[]) { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String input=br.readLine(); StringTok...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class Main{ BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreTokens()) str = new StringTokenizer(in.readLine()); ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = map(int, input().split()) lo = [] hi = [] move = x0 for _ in range(n): s, e = map(int, input().split()) s, e = sorted([s, e]) lo.append(s) hi.append(e) left = max(lo) right = min(hi) if right < left: print(-1) elif x0 < left: print(left - x0) elif x0 > right: print(x0 - right) else: ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
# t = int(input()) def solve(): pass result = [] for i in range(1): n, x0 = [int(x) for x in input().strip().split(' ')] overlap = [0] * 1001 for j in range(n): a, b = [int(x) for x in input().strip().split(' ')] if b < a: a, b = b, a for k in range...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x=map(int,input().split()) mini=[] maxx=[] for i in range(n): a,b=map(int,input().split()) mini.append(min(a,b)) maxx.append(max(a,b)) if max(mini)>min(maxx): print(-1) elif x>min(maxx): print(x-min(maxx)) elif max(mini)>x: print(max(mini)-x) else: print(0)
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import static java.lang.Math.max; import static java.lang.Math.min; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public c...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; public class Main{ public static void main(String args[] ) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE; bool...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import sys import copy import math inp = sys.stdin.readline().strip().split(" ") men, init = int(inp[0]), int(inp[1]) mmax = float('inf') mmin = 0 for i in range(0, men): inp = sys.stdin.readline().strip().split(" ") inp = sorted([int(x) for x in inp]) curmin, curmax = int(inp[0]), int(inp[1]) #print(curmin, ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; public class Main { public static long ans(int[] a,int[] b,int x,int n){ int st=a[0]; for(int i=0;i<n;i++){ st=Math.max(st,a[i]); ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int n, x, l, r, t1, t2; int main() { scanf("%d %d", &n, &x); l = 0; r = 1000; for (int i = 1; i <= n; i++) { scanf("%d %d", &t1, &t2); if (t1 > t2) swap(t1, t2); l = max(l, t1); r = min(r, t2); } if (l > r) { puts("-1"); } else { if (x ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; long long POWER(long long a, long long p) { if (p == 0) return 1; long long b = a; for (int i = 1; i < p; i++) { b *= a; } return b; } int main() { int n, x; cin >> n >> x; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { int r, t; cin >> ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q, i, j, k, sum = 0, a, b, c, d, n, s, count = 0, count1 = 0, p = -1, r = 1001, x; cin >> n >> x; vector<pair<long long int, long long int> > v; for (i = 0; i < n; i+...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int d[1001] = {0}; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; for (int j = min(a, b); j <= max(a, b); j++) d[j]++; } int ans = 9999; for (int i = 0; i <= 1000; i++) { if (d[i] == n) { if (...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchExcep...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, m = -1, M = 1001, x; scanf("%d%d", &n, &x); for (int i = 0; i < n; i++) { int l, r; scanf("%d%d", &l, &r); if (l > r) swap(l, r); m = max(m, l); M = min(M, r); } if (m > M) printf("-1\n"); else if (x < m) printf("%...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Locale; import java.util.StringTokenizer; public class Solution implements Runnable { public static void main(String[] args) { (new Thread(new Solution())).start();...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main(void) { int m[1001] = { 0, }; int n, x; int a, b; cin.tie(0); ios::sync_with_stdio(false); cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a >> b; if (a > b) { for (int j = b; j <= a; j++) { m[j]++; } } else...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x=map(int,input().split()) li=[] pos=[x] flag=0 for i in range(n): a=list(map(int,input().split())) l,r=min(a[0],a[1]),max(a[0],a[1]) if l<=x and r>=x: li.append([l,r]) elif x<l: x=l pos.append(x) for i in li: l,r=i if x<l or r<x: flag=1 break li.append([l,r]) elif x>r: x=r pos.append...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
__author__ = 'Darren' def solve(): n, x0 = map(int, input().split()) left, right = -1, 1001 for _i in range(n): ai, bi = map(int, input().split()) if ai > bi: ai, bi = bi, ai if left > bi or right < ai: print(-1) return left = max(left, a...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class Main { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringBuilder out = new StringBuilder(); public static void main(String[] args){ int[] tmp = nextIntArray(); int n = tmp[0]; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = map(int, input().split()) c, d = -1, 1001 for i in range(n): a, b = map(int, input().split()) a, b = min(a, b), max(a, b) if d < a or c > b: print(-1) exit() else: c, d = max(a, c), min(b, d) if c <= x0 <= d: print(0) else: print(min(abs(x0 - c), abs(x0 - d)))
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, mini, maxi, a, b; int l = 0; int r = 2000; cin >> n >> x; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { cin >> a >> b; mini = min(a, b); maxi = max(a, b); l = max(l, mini); r = min(r, maxi); v.push_back(ma...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author pttrung */ public class B { public static void main(St...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; while (t--) { int n, x, ans = 0, mx = 0, mn = 1002; cin >> n >> x; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; int left = min(a, b);...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x = map(int,input().split()) count = 0 l = [] for i in range(n): a,b = map(int,input().split()) l.append([min(a,b),max(a,b)]) l.sort() a = l[0][0] b = l[0][1] flag = 0 for j in range(n): if a<=l[j][0]<=b: a = l[j][0] b = min(l[j][1],b) else: flag = 1 ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { try{ //long a=Long.parseLong(ne...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; string postFile = "test.txt"; void init() {} void solve() { int n, x0; vector<pair<int, int> > a; cin >> n >> x0; for (int _n(n), i(0); i < _n; i++) { int ai, bi; cin >> ai >> bi; if (ai < bi) a.push_back(make_pair(ai, bi)); else a.push_b...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x, i; cin >> n >> x; int a, b; int m = INT_MIN; int M = INT_MAX; for (i = 0; i < n; i++) { cin >> a >> b; if (a < b) { if (m < a) { m = a; } if (M > b) M =...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; const int N = 110; int l[N], r[N]; int x0, n; int flag; void input() { scanf("%d%d", &n, &x0); int a, b; for (int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); if (a > b) swap(a, b); if (a == b) flag = true; l[i] = a, r[i] = b; } } void init() { sor...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.ArrayList; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.math.BigInteger; import ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.Scanner; import static java.util.Arrays.deepToString; public class B { public static void main(String[] args) { int i, j; int a, b; int n, x0; int min, max; int left, right; Scanner sc = new Scanner(System.in); left = -1; right = 1001; n = sc.nextInt(); x0 = sc.nextInt(); fo...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; int main() { long long i, j, k, n, p, t, a, b, kk; cin >> n >> p; a = 0; vector<pair<long long, long long> > v; for (long long(i) = (0); (i) < (n); ++(i)) { cin >> j >> k; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; void origi() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); } void tiranga() { int n, a; vector<int> r; vector<int> l; cin >> n >> a; for (int i = 0; (int)i < n; i++) { int x, y; cin >> x >> y; if (x > y) swap(x, y); r...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
A=list(map(int,input().split())) n,x=A[0],A[1] lst=[] for i in range(n): a=sorted(list(map(int,input().split()))) lst.append(a) arr=set(range(lst[0][0],lst[0][1]+1)) for i in range(0,len(lst)): arr=arr.intersection(set(range(lst[i][0],lst[i][1]+1))) if len(arr)==0: print('-1') else: if min(arr)<...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.Scanner; public class _0814YoungPhotographer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int x=sc.nextInt(); int leftRange=-1; int rightRange=Integer.MAX_VALUE; for(int i=0;i<n;i++) { int pos1=sc.nextInt(); int pos2=sc.next...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x = [int(x) for x in input().split()] m1 = -1 m2 = 9999999 for i in range(n): a, b = [int(x) for x in input().split()] m1 = max(m1, min(a, b)) m2 = min(m2, max(a, b)) if m1 > m2: print(-1) exit() if x < m1: print(m1 - x) elif x >= m1: if x <= m2: print(0) else: ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.Arrays; public class exp { static Reader in; static PrintWriter out; static class point implements Comparable<point> { int x,type; public point (int x,int type) { this.x=x; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class B { private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int a[1005]; int main() { int l, r, n, x; cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> l >> r; if (l > r) swap(l, r); a[l]++; a[r + 1]--; } int tmp1 = 0; int minn = 1e4 + 4; for (int i = 0; i <= 1000; i++) { t...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; public class P14B { public static void main(String [] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int left = 0; int right = 1001; int result = 0; for (int i = 0; i < n; i++) { int ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, x; cin >> n >> x; long long a[n], b[n]; long long min_ending_point = 10005; long long max_starting_point = -1; for (long long i = 0; i < n; i++) { long long ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
k, s = map(int, input().split()) x, y = map(int, input().split()) if x > y: x, y = y, x for i in range(k - 1): a, b = map(int, input().split()) if a > b: if b > x: x = b if a < y: y = a else: if a > x: x = a if b < y: y = b if x > y: print(-1) elif s < x: print(x - s) elif s ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, R = 2000, L = 0; cin >> n >> m; for (x, y; cin >> x >> y;) { if (x > y) swap(x, y); L = max(x, L); R = min(y, R); } cout << (L > R ? -1 : m >= L && m <= R ? 0 : L > m ? L - m : m - R) << endl; }
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
//package B; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Young_Photographer { int xo; int n; int a, b; int A = -1; int B = 1001; public static void main(String[] args) throws IOException { Young_Photographer y = new Young_...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; inline bool isvowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); } template <class T> void print(const T &cont) { for (auto x : cont) cout << x << ' '; cout << '\n'; } void input() { int n, x, a, b; cin >> n >> x; int low = 0, hig...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a, b, in[100], on[100], i = 0, r, y; cin >> n >> x; int t = n; while (t--) { cin >> a >> b; r = min(a, b); y = max(a, b); in[i] = r; on[i] = y; i++; } sort(in, in + n); sort(on, on + n); if (in[n - 1] < on[0]) {...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x0=map(int,input().split()) x=[0]*1001 c=0 for i in range(n): a,b=map(int,input().split()) if a>b: a,b=b,a c+=1 for i in range(a,b+1): x[i]+=1 if x[x0]==n: print(0) exit() ans=1e9 for i in range(x0+1,1001): if x[i]==n: ans=min(ans,i-x0) break for i in range(...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n >> x; int lbound = 0, rbound = 1020; while (n--) { int l, r; cin >> l >> r; if (l > r) swap(l, r); lbound = max(lbound, l); rbound = min(rbound, r); } int l = lbound, r = rbound; if (l > r) cout << -1; el...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = [int(x) for x in raw_input().strip().split()] l = 0 r = 1000 for i in xrange(n): a, b = [int(x) for x in raw_input().strip().split()] if a > b: a, b = b, a if a > l: l = a if b < r: r = b if l > r: break if l > r: print '-1' elif l <= x0 <= r: print '0' elif x0 < l: ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.Arrays; import java.util.Scanner; public class YoungPhotographer { public static void main(String[] args) { Scanner input=new Scanner(System.in); int n=input.nextInt(); int x=input.nextInt(); int[] m=new int[1001]; Arrays.fill(m, 0); for (i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w')...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.*; public class code { static PrintWriter pw; static boolean[] visit; static ArrayList<Pair>[] adj; static ArrayList<Integer> list; static long max=01; static void dfs(int i, long c) { visit[i]=true; max=Math.max(c, max); for(Pair p: adj[i]) { if(!visit[p.x-1]) { df...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x=map(int,input().split(' ')) lst=[] for i in range(n): temp=[] a1,b1=map(int,input().split(' ')) a=min(a1,b1) b=max(a1,b1) for j in range(a,b+1): temp.append(j) lst.append(set(temp)) result=lst[0] for i in range(1,len(lst)): result=result.intersection(lst[i]) result=list(result) r...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int n, x, a, b, mx = -1, mn = 1e8; int main() { cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a >> b; if (a > b) swap(a, b); mx = max(mx, a); mn = min(mn, b); } if (mx > mn) cout << -1; else if (x >= mx && x <= mn) cout << 0; else i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.lang.*; import java.util.*; public class Abhishek { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int[][] s = new int[n][2]; for (int i = 0; i < n; i++) { in...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed; cout.precision(10); long long int t; t = 1; while (t--) { long long int n, x, m = -1, l = INT_MAX; cin >> n >> x; for (long long int i = 0; i < n; i++) { long long i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
def main(): n, x = map(int, input().split()) #n:Número de casos, x:Posición inicial del fotógrafo pos0 = [] #Posición de los corredores pos1 = [] for _ in range(n): temp = list(map(int, input().split())) pos0.append(min(temp)) pos1.append(max(t...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
def detedge(f,s): n=[0,0] if f[1]<s[0]: return 0 n[0]=max(f[0],s[0]) n[1]=min(f[1],s[1]) return n def detres(v,xo): edg=v[0] for c in v: edg=detedge(edg,c) #print(edg) if edg==0: print(-1) return if edg[0]<=xo<=edg[1]: print(0) return elif edg[0]>xo: print(edg[0]-xo) else: print(xo-edg[...