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...
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { StreamTokenizer in; PrintWriter out; public static void main(String[] args) throws IOException { new Main().run(); } public void run() throws IOException { //in =new StreamTokenizer(new Buf...
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 int INF = 1000000000000000000; const long long int mod = 1E9 + 7; void solve() { long long int n, x; cin >> n >> x; long long int a, b; vector<long long int> l, r; for (int i = 0; i < n; i++) { cin >> a >> b; l.push_back(min(a, b)); r.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 sys import os from io import IOBase, BytesIO # import heapq import math # import collections # import itertools # import bisect mod = 10 ** 9 + 7 pie = 3.1415926536 # import resource # resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) # import threading # threading.stack_size(2**27...
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; cin >> n >> x; int a[n], b[n], l = x; for (int m = 0; m < n; m++) { cin >> a[m] >> b[m]; if (a[m] > b[m]) { int l = a[m]; a[m] = b[m]; b[m] = l; } if (x < 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...
n,x=map(int,input().split()) l1=sorted(map(int,input().split())) flag,z1,z2=0,[l1[0]],[l1[1]] for i in range(n-1): l=sorted(map(int,input().split())) z1.append(l[0]) z2.append(l[1]) if l1[0]<l[0]:l1[0]=l[0] if l1[-1]>l[-1]:l1[-1]=l[-1] if max(z1)>min(z2):print("-1") elif x<l1[0]:print(l1[0]-x) elif x>l1[-1]:print(...
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()) x1, x2 = 0, 1000 for i in range(n): a, b = map(int, input().split()) x1 = max(x1, min(a, b)) x2 = min(x2, max(a, b)) print(max(0, x1 - x0, x0 - x2) if x2 >= x1 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; const int N = 110; const int INF = 10000000; int a[N], b[N]; int n, x0; int main() { int i, j; scanf("%d%d", &n, &x0); for (i = 0; i < n; i++) { scanf("%d%d", &a[i], &b[i]); if (a[i] > b[i]) swap(a[i], b[i]); } int minerg = INF; bool p = false; 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...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x; cin >> n >> x; long long int mn = INT_MIN; long long int mx = INT_MAX; for (long long int i = 0; i < n; i++) { long long int a, b; cin >> a >> b; long long int p = min(a, b); if (a != p) { swap(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...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @auth...
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 exit n,x=map(int,input().split()) start=0;end=1001; for i in range(n): i,j=map(int,input().split()) start1=min(i,j);end1=max(i,j); start=max(start,start1);end=min(end,end1); if(start>end):print(-1);exit(0) if(start<=x<=end):print(0);exit(0) print(min(abs(start-x),abs(end-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.awt.Point; import java.io.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Main{ static class Run implements Runnable{ //TODO parameters final boolean consoleIO = true; final String inFile = "input.txt"; ...
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 asd[])throws Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); int x=in.nextInt(); int m[]=new int[1001]; for(int i=0;i<n;i++) { int a=in.nextI...
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; const int Max = 1010; int tbl[Max]; memset(tbl, 0, sizeof(tbl)); for (int i = 0; i < n; ++i) { int start, end; cin >> start >> end; if (start > end) { swap(start, end); } for (int i = start; 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, a, b, ax = 0, bx = 1000; cin >> n >> x; int r = 0; for (int i = 0; i < n; i++) { cin >> a >> b; if (a > b) swap(a, b); ax = max(ax, a); bx = min(bx, b); if (ax > bx) { r = -1; break; } } if (r == -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 java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B14 implements Runnable { final int INF = Integer.MAX_VALUE; 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...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; bool check1 = 1, check2 = 1; cin >> n >> x; vector<pair<int, int> > arr(n); for (int i = 0; i < n; i++) { cin >> arr[i].first >> arr[i].second; if (arr[i].first > arr[i].second) { int temp = arr[i].first; arr[i].first = 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() { long long t, n, s, ans = 0; cin >> t >> s; long long a[t], b[t]; for (int i = 0; i < t; i++) { cin >> a[i] >> b[i]; if (s < min(a[i], b[i])) { ans += (min(a[i], b[i]) - s); s = min(a[i], b[i]); } if (s > max(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...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Random; public class B216{ void solve() { int n = ni(), x = ni(); int[][] a = new int[n][]; for(int i=0;i<n;i++) { a[i] = ia(2); Arrays...
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()) l1=0 l2=1000 f=0 for i in range(n): a,b=map(int,input().split()) if(a>b): a,b=b,a if(a<l1 and b<l1 or a>l2 and b>l2): f=1 else: l1=max(a,l1) l2=min(b,l2) if(f==0): if(k>=l1 and k<=l2): print(0) elif(k<l1): prin...
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,m = map(int,input().split()) y=list((map(int,input().split()))) s= min(y) e= max(y) n-=1 while(n): y[0],y[1]=map(int,input().split()) a=min(y) b=max(y) if(a>s):s=a if(b<e):e=b n-=1 if(e-s<0):print(-1) elif s<=m<=e : print(0) else : print((s-m) if m<s else (m-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...
n, x = [int(i) for i in input().split()] a = [[int(j) for j in input().split()] for i in range(n)] p1 = max([(min(i))for i in a]) p2 = min([(max(i))for i in a]) if p2 < p1: print(-1) else: if x < p1: print(p1 - x) elif x > p2: print(x - p2) 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.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; public class Main { public static void main(String[] args) throw...
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; /** * * @author epiZend */ public class Photographer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int endsFirst = 1000; int startsLast = 0; int n = sc.nextInt(); int x0 = sc.nextInt(); 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; int f[10005]; int main() { int n, x; scanf("%d %d", &n, &x); int mn = 100000007, mx = 0; for (int i = 1; i <= n; ++i) { int a, b; scanf("%d %d", &a, &b); if (b < a) swap(a, b); for (int j = a; j <= b; ++j) ++f[j]; mn = min(mn, a); mx = max(mx...
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 & has2 if len(has) == 0: print(-1) elif x0 in has: print(0) elif x0 < min(has): print(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...
b,c = map(int,input().split()) mi = [] ma = [] l = 0 for x in range(b): d,e = map(int,input().split()) mi.append(min(d,e)) ma.append(max(d,e)) mi.sort() ma.sort() if mi[-1] > ma[0]: print(-1) else: if c < mi[-1]: print(mi[-1]-c) elif c > ma[0]: print(c-ma[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() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, now, le, ri, left = 0, right = 1000; cin >> n >> now; for (int i = 0; i < n; ++i) { cin >> le >> ri; if (ri < le) swap(le, ri); left = max(le, left); right = min(ri, 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; void debugMode() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { debugMode(); int n, x; cin >> n >> x; int L = 0, R = 1000; while (n--) { int a, b; cin >> a >> b; if (a > b) swap(a, b); L = max(L, a); R = min(R, 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.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int x0 = scanner.nextInt(); int start = Integer.MIN_VALUE; int end = Integer.MAX_VALUE; boo...
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 l1, l2; cin >> l1 >> l2; if (l1 > l2) swap(l1, l2); n--; while (n--) { int x, y; cin >> x >> y; if (x > y) swap(x, y); if ((x <= l1 && y >= l1) || (x <= l2 && y >= l2) || (x >= l1 && y <= l2)) { 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.io.*; import java.util.*; import java.math.*; public class P14B { public void run() throws Exception { int n = nextInt(); int x0 = nextInt(); int lo = 0; int hi = 1000; for (int i = 0; i < n; i++) { int a = nextInt(); int b = nextInt(); if (a < b) { lo = 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...
#include <bits/stdc++.h> const double EPS = 1e-9; const int MOD = 1000003; const int INF = 2000 * 1000 * 1000; const int MAX = 4000000; using namespace std; int popcount(int n) { bitset<32> b(n); return b.count(); } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int 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...
while True: try: def soln(n, k): l, r = -10e6, 10e6 for i in range(n): a, b = map(int, input().split()) a, b = min(a, b), max(a, b) l = max(l, a) r = min(r, b) if l > r:print("-1") elif k < l:print(l-k) elif k > r:print(k -r) else:print("0") def read(): n, k = map(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,x = map(int,input().split()) mi = 0 ma = 1000 k = 0 for i in range(n): a = list(map(int,input().split())) a1 = min(a) b1 = max(a) if a1>ma or b1<mi: k = 1 print(-1) break else: if a1>mi: mi = a1 if b1<ma: ma =b1 if k==1: pass else: if x<mi: print(mi-x) elif x>ma: print(x-ma) else: print...
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.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Scanner; import java.util.Vector; public class Main{ pu...
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, y, z; scanf("%d%d", &n, &x); y = 0; z = 1000; for (int i = 0; i < n; i++) { scanf("%d%d", &a, &b); if (a > b) { int t = a; a = b; b = t; } y = a > y ? a : y; z = b < z ? b : z; } if (y > z) ...
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...
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...
import java.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class solver implements Runnable { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer tok = new 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.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class A { static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader =...
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 heapq import sys import unittest def dosolve(inf): n,x0 = map(int,inf.readline().split()) a,b = map(int,inf.readline().split()) if b < a: a,b = b,a ar,br = a,b for i in range(n-1): a,b = map(int,inf.readline().split()) if b < a: a,b = b,a if br < a: return -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 java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
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 File { public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { 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; int main() { int n, x0, ans = 0, i, j, l, r, amax = -1, bmin = 1001; cin >> n >> x0; vector<int> a(n), b(n); bool t; for (i = 0; i < n; i++) { cin >> l >> r; a[i] = min(l, r); if (a[i] > amax) amax = a[i]; b[i] = max(l, r); if (b[i] < bmin) bmi...
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 B14 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int now = Integer.par...
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 mod = 1e9 + 7; const int inf = INT_MAX; const double eps = 1e-9; const double pi = acos(-1.0); int cnt[1100]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, x, ans = inf; cin >> n >> x; for (int i = 0; i < n; i++) { int a, b; 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() { int n, x; cin >> n >> x; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] > b[i]) { swap(a[i], b[i]); } } sort(a, a + n); sort(b, b + n); if (a[n - 1] > b[0]) { cout << -1; } else if (a[n - 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, p[2000]; int main() { cin >> n >> x; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; if (a > b) { swap(a, b); } p[a]++; p[b + 1]--; } for (int i = 1; i <= 1000; i++) { p[i] = p[i] + p[i - 1]; } int mn = 1e9; ...
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()) left = 0 right = 1000 for i in range(n): a, b = sorted(map(int, input().split())) left = max(left, a) right = min(right, b) if left <= right: if x0 < left: print(left - x0) elif x0 > right: print(x0 - right) else: print(0) else: print...
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()) final_position = -1 left = [] right = [] for _ in xrange(n): pair = map(int, raw_input().split()) pair.sort() left.append(pair[0]) right.append(pair[1]) left = max(left) right = min(right) if left <= right: if x < left: print left - x elif x > right: print x - right 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...
import sys # from pprint import pprint def main(): all_input = iter(sys.stdin.read().strip().replace('\n', ' ').split(' ')) n = int(all_input.next()) x0 = int(all_input.next()) road = [0]*1001 for i in xrange(n): a = int(all_input.next()) b = int(all_input.next()) if 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...
import java.util.*; import java.io.*; public class a { static long mod = 1000000007; public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = input.nextInt(), x = input.nextInt(); int[] data = new int[100...
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 from heapq import heapify,heappush,heappop,heappushpop from collections import defaultdict as dd, deque as dq,Counter as C from bisect import bisect_left as bl ,bisect_right as br from itertools import combinations as cmb,permutations as pmb from math import factorial as f ,ceil,gcd,sqrt,lo...
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 = 1006; int a[maxn]; int main() { int n, x; scanf("%d%d", &n, &x); for (int i = 1; i <= n; i++) { int l, r; scanf("%d%d", &l, &r); if (l > r) swap(l, r); a[l]++; a[r + 1]--; } int tmp = 0; int ans = 1e9; for (int 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...
def r(): return map(int,raw_input().split()) n,x0 = r() up = 1000 l = [0]*(up+1) for i in range(0,n): a,b = r() if a>b: a,b = b,a for j in range(a,b+1): l[j]+=1 lst = [abs(p-x0) for p,v in enumerate(l) if v==n] print -1 if len(lst)==0 else min(lst)
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 input().split()] intersections = [] for _ in range(n): a,b = [int(x) for x in input().split()] a,b = min(a,b), max(a,b) if n==1 and a<= x0 <=b: print('0') exit() if intersections: currentRange = list(range(a,b+1)) inersectionOfCurrentAndPrevious =...
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 gc import sys from io import BytesIO, IOBase from collections import Counter from collections import deque import heapq import math import statistics def sin(): return input() def ain(): return list(map(int, sin().split())) def sain(): return input().split() def iin(): return int(si...
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; public class Q14B implements Runnable { private void solve() throws IOException { int n = nextInt(); int x = nextInt(); int start = Integer.MIN_VALUE, stop = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { int s = 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...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; long long x, y, mi, ma; cin >> x >> y; if (x < y) { mi = x; ma = y; } else { mi = y; ma = x; } for (long long i = 1; 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; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string gets() { char ch[600]; scanf("%s", ch); return ch; } template <class P, class Q> inline P smin(P &a, Q b) { if (b < a) a = b; return a; } template <class P, class Q> inline P smax(P &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 a, b, n, x, u, v; a = 0; b = 1000; cin >> n >> x; for (int i = 1; i <= n; ++i) { cin >> u >> v; if (u > v) swap(u, v); a = max(a, u); b = min(b, v); } if (a > b) cout << -1 << endl; else if ((x <= b) && (x >= a)) 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...
#include <bits/stdc++.h> using namespace std; int main() { int n, st; cin >> n >> st; int l = 0, r = 1e9; pair<int, int> p; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x < y) { p.first = x; p.second = y; } else { p.first = y; p.second = x; } if (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.ArrayList; import java.util.Scanner; /** * * @author Hartha */ public class YoungPhotographer { public static ArrayList inte(int a, int b) { ArrayList<Integer> temp = new ArrayList<Integer>(); for(int i = a; i <= b; i++) temp.add(i); return 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,x=map(int,input().split()) a=[0]*n b=[0]*n c=[] d=[] for i in range (0,n): a[i],b[i]=map(int,input().split()) a[i],b[i]=min(a[i],b[i]),max(a[i],b[i]) s=min(b) t=max(a) if s<t: print(-1) else: if t<=x<=s: print(0) else: print(min(abs(x-t),abs(x-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.* ; public class Main { public static void main(String [] args) { Scanner s=new Scanner (System.in); int n=s.nextInt(); int x0=s.nextInt(); int [] a=new int[1005]; int [] b=new int[1005]; int x,y; 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 findMaxElement(vector<int> A) { int max_value = A[0]; for (int i = 0; i < A.size(); i++) { if (A[i] > max_value) max_value = A[i]; } return max_value; } int findMinElement(vector<int> A) { int min_value = A[0]; for (int i = 0; i < A.size(); i++) { 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...
/* /$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ |__ $$ /$$__ $$ |$$ |$$ /$$__ $$ | $$| $$ \ $$| $$|$$| $$ \ $$ ...
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, x0, le, ri; scanf("%d%d", &n, &x0); le = -1; ri = 1005; bool flag = true; for (int i = 0; i < n; ++i) { int a, b; scanf("%d%d", &a, &b); if (flag == false) { continue; } if (a > b) swap(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, x0 = list(map(int, input().rstrip().split())) x = [0] * 1002 for _ in range(n): a, b = list(map(int, input().rstrip().split())) x[min(a,b)] += 1 x[max(a,b) + 1] += -1 minD = 1002 arr = [0] * 1001 arr[0] = x[0] if arr[0] == n: minD = abs(0 - x0) for i in range(1, len(arr)): arr[i] += arr[i - 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, T; int x = 0, y = 2000; void read() { int a, b; cin >> N >> T; for (int i = 1; i <= N; i++) { cin >> a >> b; x = max(x, min(a, b)); y = min(y, max(a, b)); } } int main() { read(); if (y < x) cout << -1 << endl; else if (x <= T && y >= 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...
# copied n,x0 = map(int, raw_input().split()) L,R = 0,1001 for i in xrange(n): l,r = sorted(map(int, raw_input().split())) L = max(L,l) R = min(R,r) print -1 if L > R else max(0,L-x0,x0-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...
import java.util.*; import java.io.*; public class JAVA{ public static void main(String args[]) throws Exception{ Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = sc.nextInt(); int x = sc.nextInt(); int a[] = new int[n]; int b[] = new 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, i, a, b, m, M; cin >> n >> x; vector<pair<int, int> > vec; for (i = 0; i < n; i++) { cin >> a >> b; if (a > b) swap(a, b); vec.push_back({a, b}); } m = vec[0].first; M = vec[0].second; for (auto i : vec) { m = max(m, 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, x0 = map(int, input().split()) x1, x2 = 0, 1000 for i in range(n): a, b = map(int, input().split()) x1 = max(x1, min(a, b)) x2 = min(x2, max(a, b)) print(max(0, x1 - x0, x0 - x2) if x2 >= x1 else -1) # Made By Mostafa_Khaled
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, a, b, maxa = -1, minb = 1e9, ans = 0; cin >> n >> x0; while (n--) { cin >> a >> b; if (a > b) swap(a, b); maxa = max(maxa, a); minb = min(minb, b); } if (maxa > minb) cout << "-1"; else if (x0 >= maxa && x0 <= minb) ...
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, 1000 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(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.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class YoungPhotographer implements Closeable { private InputReader in = new InputReader(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...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static...
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 long n, x; cin >> n >> x; pair<long long, long long> p; cin >> p.first >> p.second; long long m1 = min(p.first, p.second); long long m2 = max(p.first, p.second); p.first = m1; p.second = m2; long long flag = 0; for (long long i = 1; 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 double pi = 3.1415926535897932384626433832795; int main() { int n, x0; cin >> n >> x0; vector<int> a(n), b(n); for (int i = 0; i < (n); i++) cin >> a[i] >> b[i]; for (int i = 0; i < (n); i++) if (a[i] > b[i]) swap(a[i], b[i]); int cnt[5000] = {}; 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...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; public class MainTest { public static void main(String[] args) { //InputReader in = new InputReader(System.in); Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(Syst...
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; public class YoungPhotographer { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedRe...
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 primaryTest; import java.util.Arrays; import java.util.Scanner; public class CF14B { private void run(Scanner in) { int n = in.nextInt(); int x = in.nextInt(); int[][] sport = new int[n][2]; int[] flag = new int[n]; int minNum = 0; int maxNum = 0; int minUp = 1001;// 最小上限 int maxDown = -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 ch(int x); int fun(int x, int y, int p, int a, int vb, int vs); int i; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, x, lo = -1000, up = 1001, t1, t2; cin >> n >> x; for (int i = 0; i < n; i++) { int n1, n2; 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...
n,m=map(int,input().split()) arr=[] for i in range(0,n): x,y=map(int,input().split()) if x-y>0: t=x x=y y=t p=(x,y) arr.append(p) # print(arr) max1=-1 min1=100000 for i in range(0,n): if max1<arr[i][0]: max1=arr[i][0] if min1>arr[i][1]: min1=arr[i][1] # 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...
/* * @author Sane * Created on 10.05.2012 at 13:48:07 */ import java.util.*; import java.util.Scanner; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.OutputStream; import java.io.PrintWrite...
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.*; public class Main{ public static void main(String args[]) { MyScanner scanner = new MyScanner(); int n = scanner.nextInt(), x = scanner.nextInt(), t, cMin = scanner.nextInt(), cMax =...
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,1001 for i in xrange(n): l,r = sorted(map(int, raw_input().split())) if l > L: L = l if r < R: R = r L = x0 if L == 0 else L R = x0 if R == 1001 else R if L<=R: if x0 < L: print L-x0 elif x0 > R: print x0-R else: print 0 else: print -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 java.io.*; import java.math.*; import java.util.*; public class Main { static MyScanner in = new MyScanner(); static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static long H,W; static BitSet bs; static long mod = 1000000007; public static void mai...
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.math.BigDecimal; import java.math.BigInteger; public class Main { static void solve(InputReader in, OutputWriter out) throws IOException { // Scanner in = new Scanner(new BufferedReader(new // FileReader("input.txt"))); // PrintWriter out = ...
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 itertools import * n, x = map (int, raw_input ().split ()) l, r = -1, 10000 for _ in xrange (n): a, b = sorted (map (int, raw_input ().split ())) l, r = max (l, a), min (r, b) print -1 if l > r else max (0, 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...
#include <bits/stdc++.h> using namespace std; int n, x, a, b, m, l = 1002; void center(int a, int b, int &m, int &l) { m = max(m, a); l = min(l, b); } int main() { cin >> n >> x; while (n--) { cin >> a >> b; if (a > b) swap(a, b); center(a, b, m, l); } cout << (m > l ? -1 : x < m ? m - x : 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...
import java.lang.*; import java.util.*; import static java.lang.Math.*; public class Main{ public static boolean intersect(int a1, int b1, int a2, int b2){ if(max(a1, a2) <= min(b1, b2)){ return true; } return false; } public static void main(String... argv){ int x, n; Scanner cin = new Scanner(System...
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 init(int n) { if (n < 0) return -n; return n; } int main() { int n, x; while (scanf("%d%d", &n, &x) != EOF) { int min_val = 0x3f3f3f3f, max_val = -0x3f3f3f3f; int a, b; while (n--) { scanf("%d%d", &a, &b); if (a > b) { int t = a; a = b; ...
Problem: <image> William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money. Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone wants to book the flat from day l_i until day r_i inclusive. To avoid ...
/* KAMUI! ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓██████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓███▓▒▒░▒▒▒▒▒░░░▒▒▒▓▓███▓▓▓▓▓▓▓ ▓▓▓▓▓▓█▓▒▒▒▓▓████████▓▒▒░▒▒▒▓██▓▓▓▓▓▓ ▓▓▓▓██▒▓████████████████▓░▒▒▒▒▓██▓▓▓▓ ▓▓▓██▓███████▓▒░░░░░░░▒███▒░░▒▒▒██▓▓▓ ▓▓█████████▓░░░░░░░░░░░░░██▓▓██████▓▓ ...
Problem: <image> William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money. Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone wants to book the flat from day l_i until day r_i inclusive. To avoid ...
// --------------------------------------------------<TEMPLATE>-------------------------------------------------- // --------------------<optimizations>-------------------- /* #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,fma") */ // -------------------</optimizations>-------------------- /...
Problem: <image> William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money. Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone wants to book the flat from day l_i until day r_i inclusive. To avoid ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int INF = 1e9; int n, m; pair<int, int> offers[N]; vector<int> size_list[N]; int res[N]; struct Node1D { int val; Node1D *l_child, *r_child; Node1D() { val = INF; l_child = r_child = nullptr; } void Add(int l, int r, int...
Problem: <image> William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money. Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone wants to book the flat from day l_i until day r_i inclusive. To avoid ...
// Author: wlzhouzhuan #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pb push_back #define fir first #define sec second #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define mset(s...
Problem: <image> William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money. Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone wants to book the flat from day l_i until day r_i inclusive. To avoid ...
#include <bits/stdc++.h> using namespace std; #define sz(x) (int) (x).size() #define all(x) (x).begin(), (x).end() #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " <<...
Problem: <image> William owns a flat in central London. He decided to rent his flat out for the next n days to earn some money. Since his flat is in the center of the city, he instantly got m offers in the form (l_i, r_i), which means that someone wants to book the flat from day l_i until day r_i inclusive. To avoid ...
#include<bits/stdc++.h> using namespace std; int n, m, tot; int rt[131072]; int ls[131072 * 200]; int rs[131072 * 200]; int mn[131072 * 200]; void ins(int &p, int l, int r, int pos, int val){ if (p == 0){ p = ++tot; mn[p] = val; } else{ if (val < mn[p]) { mn[p] = val; } } if (l == r){ ...