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...
#include <bits/stdc++.h> using namespace std; int bk[6666]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, x0, ans = 999999, f = 0; cin >> n >> x0; for (int k = 0; k < n; k++) { int l, r; cin >> l >> r; if (l > r) swap(l, r); for (int i = l; i <= r; i++) bk[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 mymin(int x, int y) { if (x < y) return x; else return y; } int main() { int n, x0, i, j = 0, x = -1, y = 100000, ans = -1; cin >> n >> x0; int a, b, d = 0; cin >> a >> b; int ta = min(a, b); int tb = max(a, b); x = max(ta, x); y = min(y, tb)...
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...
I = lambda : map(int,input().split()) n , x = I() l = [] for i in range (n) : p , q = I() p , q = min(p,q) , max(p,q) l1 = [p,q] l.append(l1) l.sort() x1 , x2 = l[0][0] ,l[0][1] for i in l : p,q = i[0] ,i[1] x2 = min(x2,q) x1 = max(x1,p) #print(x1,x2) if x2>=x1 : if x2>=x and x>=x1 : ...
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 double eps = 1e-6; const int MAXN = 5005; const int MAXM = 5005; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const int MOD = 1000000007; const double FINF = 1e18; pair<int, int> tmp[105]; int main() { int n, m, x, y; scanf("%d%d", &n, &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() { int n, a[5005] = {0}, x, y, ans = 0x3f3f3f3f, x0; scanf("%d%d", &n, &x0); for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); if (x > y) swap(x, y); for (int j = x; j <= y; j++) { a[j]++; if (a[j] == n) { if (abs(j - x0) <...
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...
#!/usr/bin/env python n, x0 = map(int, raw_input().split()) a, b = (0, 1000) for i in range(n): at, bt = map(int, raw_input().split()) at, bt = (min(at, bt), max(at, bt)) a = max(a, at) b = min(b, bt) if a > b: print -1 elif x0 in range(a, b + 1): print 0 else: print min(abs(x0 - a), ab...
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 StreamTokenizer in = new StreamTokenizer(System.in); static int ni() throws Exception { in.nextToken();return (int)in.nval; } public static void main(String[] arges) throws Exception { int n1 = ni(); int x0 = ni(); ...
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 INF = 1e9, MOD = 1e9 + 7, ohara = 1e6; const long long LINF = 1e18; long long int n, cnt = 0, ans = 0, a, b, c, d, cmp[ohara], cmpp, m, h, w, x, y, sum[ohara], pos; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; string alph("abcdefghijklmnopq...
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 L = input() L = L.split() n = int(L[0]) x = int(L[1]) minimos = [] maximos = [] mini = 0 maxi = 1000 for k in range (n): D = input() D= D.split() D[0]=int(D[0]) D[1]=int(D[1]) D.sort() minimos.append(int(D[0])) maximos.append(int(D[1])) if int(D[0])>mini: mini = int(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...
inf = float("inf") n,x = [int(item) for item in input().split()] a = set([i for i in range(1,1000)]) l,h = inf,-inf for i in range(n): u,v = [int(item) for item in input().split()] u,v = min(u,v),max(u,v) a = a.intersection(set([i for i in range(u,v + 1)])) #print(a) if not a: print(-1) 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 a[1001]; for (int i = 0; i < 1001; i++) a[i] = 0; int N, x0; cin >> N >> x0; for (int i = 0; i < N; i++) { int b, e; cin >> b >> e; if (b > e) swap(b, e); for (int j = b; j <= e; j++) a[j]++; } int ret = 1001; for (int i = 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...
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; long long mod = 1000000007; long long kmp(string x) { long long n = x.length(); vector<long long> lcp(x.length(), 0); for (long long i = 1; i < n; i++) { long long j = lcp[i - 1]; while (j > 0 && x[j] != x[i]) j = lcp[...
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...
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): n, x0 = map(int, raw_input().split()) s = set(xrange(1001)) for i in xrange(n): a, b = map(int, raw_input().split()) s.intersection_update(set(xrange(min(a, b), max(a, b) + 1))) if len(s) != 0: print abs(sorted(list(s), 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...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; while (scanf("%d %d", &n, &x) != EOF) { int min = 0; int max = 100000; int i, big, s, a, b, z; for (i = 0; i < n; i++) { scanf("%d %d", &a, &b); if (a > b) { big = a; s = b; } else { big = ...
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()) m = -1 M = 1000000 for i in range(n): a,b = map(int,raw_input().split()) m = max(m,min(a,b)) M = min(M,max(a,b)) if M<m: res=-1 else: res = 0 if x0<m: res = m-x0 if M<x0: res = x0-M print 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...
n,x0=map(int,input().split()) pos=set() a,b=map(int,input().split()) a1=min(a,b) a2=max(a,b) for i in range(a1,a2+1): pos.add(i) for i in range(n-1): a,b=map(int,input().split()) a1=min(a,b) a2=max(a,b) L=[] for each in pos: if each not in range(a1,a2+1): L.append(each) f...
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(s) for s in input().split()] maxstart = -1 minending = 1001 for i in range(0,n): a,b = sorted([int(s) for s in input().split()]) if a > maxstart: maxstart = a if b < minending: minending = b if minending >= maxstart: if x <= maxstart: print(maxstart-x) 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 n, x; int sum[1000 + 10], f[1000 + 10]; int ABS(int x) { return x > 0 ? x : -x; } int main() { scanf("%d %d", &n, &x); for (int i = 1; i <= n; i++) { int a, b; scanf("%d %d", &a, &b); if (a > b) swap(a, b); f[a]++; f[b + 1]--; } sum[0] = f[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...
#include <bits/stdc++.h> using namespace std; int use[110][1010]; int main() { int n, x, ans; while (scanf("%d%d", &n, &x) != EOF) { memset(use, 0, sizeof(use)); int a, b; for (int i = 0; i < n; ++i) { scanf("%d%d", &a, &b); if (a > b) swap(a, b); for (int j = a; j <= b; ++j) use[i][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.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(),b=sc.nextInt(),ans=1002; int a[]=new int[1002]; for(int i=0;i<n;i++){ int u=sc.nextInt(),v=sc.nextInt(); a[Math.min(u,v)]++; a[Math.max(u...
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 : Alpha_The_Coder Created On 17/12/2020 */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class D { public static void main(String[] args) { FastScanner sc=new FastScanner(); int n=sc.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...
import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Madi */ public class Photographer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] in = sc.nextLine().split(" ")...
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 Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Ta...
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 math class DictList(dict): def __setitem__(self, key, value): try: # Assumes there is a list on the key self[key].append(value) except KeyError: # If it fails, because there is no key super(DictList, self).__setitem__(key, value) except 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...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int main() { int n, x; cin >> n >> x; v = vector<pair<int, int> >(n); for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; if (v[i].second < v[i].first) swap(v[i].first, v[i].second); } int a = v[0].first, b = v[0].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...
import java.util.Arrays; import java.util.Scanner; public class Main3 { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int x0=in.nextInt(); int[][] t = new int[n][2]; int bm=-1; int em=1001; int n1=-1; int n2=-1; for(int i=0;i<n;i++) { int 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...
les=[] first_end = (10000, 10000) last_start = (0,0) n, x0 = [int(pp) for pp in raw_input().split(' ')] for i in range(n): a,b = [int(pp) for pp in raw_input().split(' ')] a,b = min(a,b), max(a,b) les += [(a,b)] if b <= first_end[1]: first_end = (a,b) if a >= last_start[0]: last_start = (a,b) if last_start[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 java.util.*; public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int x = s.nextInt(); int a, b; int left = -1, right = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { a = s.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...
import com.sun.jdi.ArrayReference; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { FastScanner fs = new FastScanner(); int n = fs.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, x0 = map(int, raw_input().split(" ")) data = [] for x in range(n): a, b = map(int, raw_input().split(" ")) data.append((a, b)) """ n, x0 = 3, 3 data = [ [0, 7], [14, 2], [4, 6] ] #""" for x in xrange(len(data)): data[x] = list(sorted(data[x])) MAX = 1000 min_delta = MAX * 2 for x in xrange(0, MAX+...
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 Main { // static Scanner in; static PrintWriter out; static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;} public static void main(String[] args) throws Exception { // in = new Scanner(System.in); out = new PrintW...
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 P014B { public static void main(String[] args) { Scanner inScanner = new Scanner(System.in); int n = inScanner.nextInt(); int x = inScanner.nextInt(); int[] present = new int[1001]; Arrays.fill(present, 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 java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class _P014B{ Scanner sc=new Scanner(System.in); int INF=1<<28; double EPS=1e-9; int n, x0; int[] a, b; void run(){ n=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...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, l, r, lmax = 0, rmin = 999999999; cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> l >> r; if (l > r) swap(l, r); if (l > lmax) lmax = l; if (r < rmin) rmin = r; } if (lmax > rmin) { cout << -1; return 0; } 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.util.*; import java.io.*; import java.util.regex.*; public class Codeforces{ static class MyScanner{ BufferedReader br; StringTokenizer st; MyScanner(FileReader fileReader){ br = new BufferedReader(fileReader); } MyScanner(){ br = new BufferedReader(new InputStreamReader(System.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() { long n, xo; long a[200], b[200], temp, kq, vt; cin >> n >> xo; for (long i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if (a[i] > b[i]) { temp = a[i]; a[i] = b[i]; b[i] = temp; } } bool ok; kq = -1; for (long i = 0; 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 P14B { P14B(){ Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int x0 = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); int minA; int minB; if ( a <= b){ minA = 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...
#include <bits/stdc++.h> using namespace std; int main() { int long long a, b, i, j, minn = -10000000, maxn = 100000; cin >> a >> b; for (i = 1; i <= a; i++) { int long long c, d; cin >> c >> d; minn = max(minn, min(c, d)); maxn = min(maxn, max(c, d)); } if (minn > maxn) { cout << -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...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; vector<pair<int, int>> v; int ans = 100000; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); v.push_back({a, b}); } for (int i = 0; i <= 1000; i++) { bool flag = true; f...
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=list(map(int,input().split())) l=[] for i in range(n): a,b=list(map(int,input().split())) if a>b: t=a a=b b=t l.append([a,b]) a=0 b=1000 f=1 for i in range(n): if a>l[i][1] or b<l[i][0]: f=0 break if l[i][0]>=a: a=l[i][0] if l[i][1]<=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.io.*; import static java.lang.Math.*; import java.math.*; public class Main { static BufferedReader in; static StringTokenizer st = new StringTokenizer(""); public static void main(String [] args) throws Exception { Locale.setDefault(Locale.US); in = new BufferedReader(new 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; long long lcm(long long a, long long b); long long gcd(long long a, long long b); long long cross_prod(long long ax, long long ay, long long bx, long long by, long long cx, long long cy); long long sum_digit(long long A); long long get_mask(long long 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 n, x, L, R = 1000; int main() { cin >> n >> x; for (int a, b; cin >> a >> b;) { if (a > b) swap(a, b); L = max(L, a), R = min(R, b); } cout << (L > R ? -1 : L <= x && R >= x ? 0 : L > x ? L - x : x - 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...
n,x0=[int(s) for s in input().split()] left=[0]*n right=[0]*n for i in range(n): a=[int(s) for s in input().split()] a.sort() left[i],right[i]=a a=max(left) b=min(right) if a>b: print(-1) else: if a<=x0<=b: print(0) else: print(min(abs(a-x0),abs(b-x0)))
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 t; int i, j, k; int m, n; int a, b; int num; while (scanf("%d%d", &n, &m) != EOF) { a = 0; b = 1000; while (n--) { scanf("%d%d", &j, &k); if (j > k) { i = k; k = j; j = i; } if (j > 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...
#include <bits/stdc++.h> using namespace std; int n, x0; void caso() { int mini, maxi, x, y; bool ok = 1; for (int i = 0; i < n; ++i) { cin >> x >> y; if (i == 0) { mini = min(x, y); maxi = max(x, y); } else { if (mini <= min(x, y) && min(x, y) <= maxi) mini = min(x, y); if (mi...
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 YoungPhotographer { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x0 = in.nextInt(); int[] bounds = new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE }; for (int 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; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { fast(); int n, x; cin >> n >> x; int n1 = n; int a[10001] = {0}; while (n--) { int v1, v2; cin >> v1 >> v2; if (v1 > v2) swap(v1, v2); for (int i = v1; v2 >= 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...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a, b; cin >> a >> b; long long x1 = 0, y1 = 1000; for (int i = 0; i < a; i++) { long long t1, t2; cin >> t1 >> t2; x1 = max(x1, min(t1, t2)); y1 = min(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...
import sys def two(): n,x = map(int,sys.stdin.readline().strip().split()) range = [0,1000] for each in xrange(0,n): l,r = map(int,sys.stdin.readline().strip().split()) l,r = min(l,r),max(l,r) if l > range[0]: range[0] = l if r < range[1]: range[1] = 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 main() { int n, x, cnt = 0, sum = 0, a, b, i; cin >> n >> x; vector<pair<int, int> > v; for (i = 0; i < n; i++) { cin >> a >> b; if (a > b) swap(a, b); v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); a = v[0].first; b = v[0].second;...
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; bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) { return a.second > b.second; } long long i, j; int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); long long t = 1; while (t--) { long long n, x; cin >> n >> x; 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...
def Match(p,q,a,b): if(q<a or p>b): return -1 else: return (max(a,p), min(b,q)) m,x = map(int,input().split()) p = 0 q = 1000 flag = 0 for i in range(m): a,b = map(int,input().split()) a,b = min(a,b), max(a,b) X = Match(p,q,a,b) if(X==-1): print(-1) 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...
n, x = [int(j) for j in input().split()] ref = 1001 * [0] for j in range(n): a, b = sorted([int(j) for j in input().split()]) for k in range(a, b + 1): ref[k] += 1 def check(index): if index >= 0 and index < 1001: return ref[index] == n return False d = 0 while True: if check(x - 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...
n,x=map(int,input().split()) a=[];b=[] for i in range(n): p,q=map(int,input().split()) if p>q:p,q=q,p a.append(p);b.append(q) # arr=[] # for i in range(n): # arr.append([a[i],b[i]]) # arr.sort(key=lambda x:x[0]) # for i in range(n): # a[i]=arr[i][0];b[i]=arr[i][1] if max(a)>min(b):print(-1);exit() 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...
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.Stack; import java.util.StringTo...
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...
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author ckapr */ import java.util.*; import java.math.*; public class NewClass { public static void main(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...
import java.util.Scanner; import static java.lang.Math.max; import static java.lang.Math.min; public class B { public static void main(String[] args) { Scanner s = new Scanner(System.in); int N = s.nextInt(); int X0 = s.nextInt(); int[][] pos = new int[N][2]; int min = 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...
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException; import java.io.IOException;import java.io.PrintStream;import java.io.PrintWriter; import java.security.AccessControlException;import java.util.Arrays;import java.util.Collection; import java.util.Comparator;import java.util.List;im...
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 segments_intersect(segment1, segment2): a1 = segment1[0] b1 = segment1[1] a2 = segment2[0] b2 = segment2[1] if (a1 >= a2 and b1 <= b2): return (a1, b1) elif (a2 >= a1 and b2 <= b1): return (a2,b2) elif (b1 < a2 or b2 < a1): print(-1) exit() eli...
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...
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): n, x0 = map(int, raw_input().split()) p = list([0]*1001) for i in xrange(n): a, b = map(int, raw_input().split()) a, b = min(a, b), max(a, b) while a <= b: p[a] += 1 a += 1 a = list() for 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...
nk=input().split() n=int(nk[0]) k=int(nk[1]) a_1=[] b_1=[] c=0 for n_tr in range (n): ab=input().split() a=int(ab[0]) b=int(ab[1]) a_1.append(min(a,b)) b_1.append(max(a,b)) if (max(a_1)>k): m=max(a_1)-k if (m+k<=min(b_1)): print(m) else: print(-1) c=c+1 elif (min(...
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, m; int main() { int p, q, max, min; cin >> n >> m >> min >> max; if (min > max) { int temp = min; min = max; max = temp; } for (int i = 1; i < n; i++) { cin >> p >> q; if (p > q) { int temp = p; p = q; q = temp; } ...
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()) l,r=0,10000 for i in range(n): ai,bi=map(int,raw_input().split()) ai,bi=min(ai,bi),max(ai,bi) l=max(ai,l) r=min(bi,r) if(l>r): print -1 elif l<=x0<=r: print 0 else : print min(abs(r-x0),abs(l-x0))
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 math n, x0 = [int(x) for x in (sys.stdin.readline()).split()] vmax = 0 vmin = 1001 for i in range(n): a, b = [int(x) for x in (sys.stdin.readline()).split()] if(a > b): a, b = b, a if(b < vmax or a > vmin): print(-1) exit() if(a > vmax): ...
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()) largest_min=0 lowest_max=1000 segments=[] steps=0 for i in range(n): x,y=map(int,input().split()) mini=min(x,y) maxi=max(x,y) if x0>maxi: steps+=x0-maxi x0=maxi if x0<mini: steps+=mini-x0 x0=mini if mini>largest_min: largest_...
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,k=map(int,input().split()) a=[0]*1001 su=0 for _ in range(n): b=[int(x) for x in input().split()] l=min(b) r=max(b) su=max(r+1,su) for i in range(l,r+1): a[i]+=1 ss=1000000 for i in range(su): if a[i]==n: ss=min(ss,abs(k-i)) if ss==1000000: print(-1) else: print(ss)
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()) a=[];b=[] for i in range(n): p,q=map(int,input().split()) if p>q:p,q=q,p a.append(p);b.append(q) arr=[] for i in range(n): arr.append([a[i],b[i]]) arr.sort(key=lambda x:x[0]) for i in range(n): a[i]=arr[i][0];b[i]=arr[i][1] if a[n-1]>b[0]:print(-1);exit() if x<a[n-1]:pri...
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.StringTokenizer; /** * Created by IntelliJ IDEA. * User: Dusha * Date: 19.05.2010 * Time: 19:29:06 * To change this template use File | Settings | File Templates. */ public class Solution { public static void main(String[] args) throws IOException { Solution sol = 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...
from sys import stdin,stdout ii1 = lambda: int(stdin.readline().strip()) is1 = lambda: stdin.readline().strip() iia = lambda: list(map(int, stdin.readline().strip().split())) isa = lambda: stdin.readline().strip().split() mod = 1000000007 n, x = iia() arr = [] for i in range(n): arr.append(sorted(iia())) arr.sort(...
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 java.lang.Math; public class main{ public static void main(String []args){ Scanner s = new Scanner(System.in); int n = s.nextInt(); int x = s.nextInt(); int seg[][] = new int[n][2]; for(int i = 0;i< n;i++){ seg[i][0] = 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...
n,x=map(int,input().split()) a=[0]*n b=[0]*n for i in range(n): a1,b1=map(int,input().split()) a[i]=min(a1,b1) b[i]=max(a1,b1) amax=max(a) bmin=min(b) if amax>bmin: print(-1) else: if x<amax or x>bmin: print(min(abs(x-amax),abs(x-bmin))) 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...
#include <bits/stdc++.h> using namespace std; const int INF = ~(1 << 31); int main() { int n, x, a, b, l = 0, r = INF; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a >> b; l = max(l, min(a, b)); r = min(r, max(a, b)); } if (l > r) cout << -1 << endl; else if (l <= x && x <= r) cou...
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()) l=[0 for i in xrange(1002)] for i in xrange(n): a,b=map(int,raw_input().split()) a,b=min(a,b),max(a,b) l[a]+=1 l[b+1]-=1 ans=1003 chk=0 for i in xrange(1001): chk+=l[i] if chk==n: ans=min(ans,abs(x-i)) print ans if ans!=1003 else -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...
#include <bits/stdc++.h> using namespace std; int n, x, ll, rr, a, b; int main() { scanf("%d%d", &n, &x); ll = 0; rr = 1010; while (n--) { scanf("%d%d", &a, &b); if (a > b) swap(a, b); ll = max(ll, a); rr = min(rr, b); } if (ll > rr) printf("-1\n"); else if (ll <= x && x <= rr) pri...
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 ##sys.stdin = open('input.txt', "r") n, x = map(int, raw_input().split()) l = 0 r = 10000 for i in xrange(n): a, b = map(int, raw_input().split()) if a > b: a, b = b, a l = max(l, a) r = min(r, b) if l > r: print -1 else: if x < l: print l - x elif x > 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...
n, x = map(int, raw_input().split()) l, u = 0, 1000 for i in xrange(n): a, b = sorted(map(int, raw_input().split())) l = max(l, a) u = min(u, b) if l > u: print -1 elif x > u: print x - u elif x < l: print l - 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 java.util.Scanner; public class b_14 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int[] freq = new int[1001]; for (int i = 0; i < n; i++) { int a = in.nextInt(); 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...
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author IR_HAM */ public class YoungPhotographer { public static void main(String [] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int 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...
n, x = map(int, input().split()) a = 0 b = 1000 for i in range(n): c, d = map(int, input().split()) a = max(a, min(c, d)) b = min(b, max(c, d)) if a > b: print(-1) exit(0) if a <= x <= b: print(0) else: print(min(abs(a - x), abs(b - 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.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class Main{ public static void main(String[]args)throws IOException{ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String s=bf.readLine(); String[]sa=s.split(...
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 { public static void main(String args[]) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), x0 = sc.nextInt(); int a = -10, b = 2000, x = 0, y = 0; for(int i=0;i<n;i++) { x = sc.nextInt(); y = sc.nextInt(); 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; int main() { int a, b, n, m, i, j; cin >> n >> m; cin >> a >> b; i = max(a, b); j = min(a, b); n--; while (n--) { cin >> a >> b; j = max(j, min(a, b)); i = min(i, max(a, b)); } if (m >= j && m <= i) cout << "0"; else if (j <= i) cout ...
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; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String[] split = in.readLine().split(" "); ...
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.HashSet; import java.util.Scanner; import java.util.TreeSet; /** * * @author Hartha */ public class YoungPhotographer { public static HashSet inte(int a, int b) { HashSet<Integer> temp = new HashSet<Integer>(); for(int i = a; i <= b; i++) temp.add(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; const int maxn = 1024; int color[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, x0, fi, la; cin >> n >> x0; for (int j = 0; j != n; ++j) { cin >> fi >> la; int minn = min(fi, la); int maxx = max(fi, la); for (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> int main() { int n, x0, x, y, left, right, i, tmp; scanf("%d%d", &n, &x0); left = -2000000000; right = 2000000000; for (i = 0; i < n; i++) { scanf("%d%d", &x, &y); if (x > y) { tmp = x; x = y; y = tmp; } if (x > left) left = x; if (y < right) righ...
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(0); cin.tie(0); cout.tie(0); int n, a, b, x, l = -1, r = 1e9; cin >> n >> x; for (int qq = 0; qq < n; qq++) { cin >> a >> b; if (a > b) swap(a, b); l = max(l, a); r = min(r, b); } if (l > r) puts("-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...
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int n, x, p, min = 0, max = 1000; cin >> n >> x; p = x; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a < b) { if ((p >= a) && (p <= b)) { if (a > min) min = a; if (b < max) max = 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; long long int a[110][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, p; cin >> n >> p; long long int i, j, ans = INT_MAX; for (i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; sort(a[i], a[i] + 2); } bool flag, found...
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> const double E = 2.7182818284590452353602874713527; using namespace std; long in[100000], fn[100000]; int main() { long i, j, n, num, cn, cnt, y = 0, p, q; scanf("%ld%ld", &num, &n); for (i = 0; i < num; i++) { scanf("%ld%ld", &p, &q); in[i] = (p < q ? p : q); fn[i] = (p < q ?...
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()) freq=[0]*1002 for i in range(n): a,b=map(int,input().split()) a,b=min(a,b),max(a,b) freq[a]+=1 freq[b+1]-=1 #print(freq) for i in range(1,1002): freq[i]=freq[i-1]+freq[i] mini=10**9 #print(freq[0:10]) for i in range(0,1001): if freq[i]==n: mini=min(mini,ab...
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.StringTokenizer; import java.util.Arrays; public class Main { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter ob=new PrintWriter(System.out); StringTokenizer st=new StringTokenizer(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 mp():return map(int,input().split()) def it():return int(input()) n,x=mp() ans=0 v=[] p=[] for _ in range(n): a,b=sorted(list(mp())) v.append(a) p.append(b) ma=max(v) mi=min(p) # print(ma,mi) if ma>mi: print(-1) elif mi>=x>=ma: print(0) else: print(max((x-mi),(ma-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 sys n, p = map(int, input().split()) l, r = -1, 10**10 for i in range(n): a, b = map(int, input().split()) if a < b: if l < a: l = a if r > b: r = b else: if l < b: l = b if r > a: r = a if l > r: print(-1) sys.exit() if l <= p <= r: print(0) elif 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...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n, x, m=0, M=1000, a, b; n = cin.nextInt(); x = cin.nextInt(); while(n-- > 0) { a = cin.nextInt(); b = cin.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.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 java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Sportsmen { public static void main(String[] args) { MyInputReader in = new MyInputReader(System.in); int n = 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; long long n, x; long long a, b; long long maxn, minn = 9999; int main() { scanf("%lld %lld", &n, &x); while (n--) { scanf("%lld %lld", &a, &b); if (a > b) swap(a, b); maxn = max(a, maxn); minn = min(b, minn); } if (maxn > minn) { printf("-1\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...
#include <bits/stdc++.h> using namespace std; const int N = 1002; int freq[N]; vector<pair<int, int>> vc; int main() { int n, x; cin >> n >> x; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; vc.push_back(make_pair(a, b)); } int res = 0; int cnt = 0; int minuss = 0, pluss = 0; for (in...