description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
for _ in range(int(input())):
n = int(input())
ai = [*map(int, input().split())]
bi = [1000000000.0 + 1] * n
ok = "Yes"
for i in range(n):
new = (i + (ai[i] % n + n) % n) % n
if bi[new] != 1000000000.0 + 1:
ok = "No"
break
bi[new] = ai[i]
if 1000000000.0 + 1 in bi:
ok = "No"
print(ok)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR IF BIN_OP NUMBER NUMBER VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = [0] * len(a)
for i in range(len(a)):
b[i] = a[i] + i
c = True
for i in range(len(b)):
for j in range(len(a)):
if i != j and i != b[i] - a[j]:
if a[j] == a[(b[i] - a[j]) % n]:
c = False
break
if c == False:
break
if c == False:
print("No")
else:
print("Yes")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
import sys
try:
sys.stdin = open("Input.txt", "r")
sys.stdout = open("Output.txt", "w")
except:
pass
input = sys.stdin.readline
for testCases in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
for i in range(n):
l[i] += i
d = {}
for i in range(n):
if d.get(l[i] % n) == None:
d[l[i] % n] = 1
else:
print("NO")
break
else:
print("YES")
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
import sys
class CHilbertsHotel:
def solve(self, tc=0):
for _ in range(int(input())):
n = int(input())
a = [int(_) for _ in input().split()]
s = set()
for i in range(n):
s.add(a[i] + i)
xs = set()
for c in s:
if c >= 0:
xs.add(c % n)
else:
xs.add(n - -c % n)
mn = min(xs)
l = sorted([(item - mn) for item in xs])
if l == [i for i in range(n)]:
print("YES")
else:
print("NO")
solver = CHilbertsHotel()
input = sys.stdin.readline
solver.solve()
|
IMPORT CLASS_DEF FUNC_DEF NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
def main():
t = int(input())
for c in range(t):
n = int(input())
shift = [int(s) for s in input().split(" ")]
print(solve(n, shift))
def solve(n, shift):
a = [i for i in range(n)]
for i in range(n):
a[i] = (a[i] + shift[i]) % n
a.sort()
for i in range(n):
if i not in a:
return "NO"
return "YES"
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN STRING RETURN STRING EXPR FUNC_CALL VAR
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
from sys import stdin
def solve():
return
def main():
inp = stdin.readline
for _ in range(int(inp())):
n = int(inp())
a = list(map(int, inp().split()))
d = set()
ans = True
for i in range(n):
k = (i + a[i] % n) % n
if k in d:
ans = False
break
d.add(k)
if ans:
print("YES")
else:
print("NO")
main()
|
FUNC_DEF RETURN FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if sum(a) % n != 0:
print("NO")
continue
set_ = set()
for i in range(n):
set_.add((a[i] + i) % n)
if len(set_) != n:
print("NO")
else:
print("YES")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$.
Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
-----Input-----
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases.
The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
-----Output-----
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
-----Example-----
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
-----Note-----
In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique.
In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique.
In the fourth test case, guests $0$ and $1$ are both assigned to room $3$.
In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
|
t = int(input())
for w in range(t):
n = int(input())
l = input().split()
a = []
for i in range(n):
a.append(int(l[i]))
c = []
for i in range(n):
c.append((i + a[i]) % n)
c.sort()
band = True
for i in range(n):
band = band * (i == c[i])
if band:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, arr):
n = len(arr)
arr.sort(key=lambda x: x[1])
ans = 1
curr = 0
for i in range(1, n):
if arr[i][0] >= arr[curr][1]:
ans += 1
curr = i
return ans
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges = sorted(ranges, key=lambda x: x[1])
b = 1
a = ranges[0]
for i in range(1, len(ranges)):
if ranges[i][0] >= a[1]:
b += 1
a = ranges[i]
return b
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort()
ans = 1
end = ranges[0][1]
for i in range(len(ranges)):
if ranges[i][0] < end:
end = min(end, ranges[i][1])
else:
ans += 1
end = ranges[i][1]
return ans
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
c = 0
ranges.sort(key=lambda x: x[1])
ve = -1000000
for i in ranges:
cs = i[0]
ce = i[1]
if cs >= ve:
c += 1
ve = ce
return c
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort(key=lambda x: x[1])
end = -1
c = 0
for i in ranges:
if end <= i[0]:
c += 1
end = i[1]
return c
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
import sys
class Solution:
def max_non_overlapping(self, ranges):
count = 0
curr_max = -1
ranges = sorted(ranges, key=lambda x: x[1])
for i in ranges:
if i[0] >= curr_max and i[1] > curr_max:
count += 1
curr_max = i[1]
return count
|
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges: list):
ranges.sort(key=lambda r: r[1])
ans, lst = 1, ranges[0]
for i in range(1, len(ranges)):
l1, r1 = lst
l2, r2 = ranges[i]
if r1 <= l2:
ans += 1
lst = ranges[i]
return ans
|
CLASS_DEF FUNC_DEF VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges = sorted(ranges, key=lambda x: [x[1], -x[0]])
count, rear = 0, 0
for st, ed in ranges:
if rear <= st:
count += 1
rear = ed
return count
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
count = 0
ranges.sort(key=lambda x: x[1])
prev = -1
for i in ranges:
st, ed = i
if st >= prev:
prev = ed
count += 1
return count
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort(key=lambda x: x[1])
st = ranges[0][0]
en = ranges[0][1]
i = 1
ct = 1
while i < len(ranges):
if ranges[i][0] >= en and ranges[i][0] > st:
st = ranges[i][0]
en = ranges[i][1]
ct += 1
i += 1
return ct
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, arr):
arr.sort(key=lambda x: x[1])
arr.sort(key=lambda x: x[0])
ans = []
for i, j in arr:
while ans and ans[-1] > j:
ans.pop()
if not ans or i >= ans[-1]:
ans.append(j)
return len(ans)
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort()
total_count = 0
current_range = None
for range in ranges:
if current_range == None:
current_range = range
total_count += 1
elif range[0] > current_range[0] and range[1] < current_range[1]:
current_range = range
elif range[0] >= current_range[1]:
current_range = range
total_count += 1
return total_count
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR NONE ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort()
s = []
for i, j in ranges:
while s and s[-1] > j:
s.pop()
if not s or i >= s[-1]:
s.append(j)
return len(s)
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort(key=lambda x: x[1])
count = 1
ending = ranges[0][1]
for pair in ranges[1:]:
if pair[0] >= ending:
count = count + 1
ending = pair[1]
return count
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
result = 1
r = sorted(ranges, key=lambda x: x[1])
prev = r[0]
for i in range(1, len(r)):
if r[i][0] >= prev[1]:
result = result + 1
prev = r[i]
return result
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort(key=lambda x: x[1])
courses = []
for strt, end in ranges:
if not courses or strt >= courses[-1][1]:
courses.append([strt, end])
return len(courses)
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR RETURN FUNC_CALL VAR VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort(key=lambda x: x[1])
ma = 0
le = len(ranges)
cnt = 0
for i in range(le):
if ranges[i][0] >= ma:
ma = ranges[i][1]
cnt += 1
return cnt
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
ranges.sort(key=lambda x: x[1])
m = ranges[0][1]
count = 1
for i in range(1, n):
if m <= ranges[i][0]:
m = ranges[i][1]
count += 1
else:
continue
return count
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
count = 1
ranges.sort(key=lambda x: (x[1], x[0]))
end = ranges[0][1]
for i in range(1, n):
if ranges[i][0] >= end:
count += 1
end = ranges[i][1]
return count
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR
|
Note: This POTD is a part of Geek Summer Carnival. Solve all POTD consecutively from 5th to 10th April and get a chance to win exclusive discount vouchers on our GfG courses.
Geek wants to select the maximum number of course bundles at the Geek Summer Carnival.
You are given a finite number of courses and N range of numbers each depicting a bundle of courses. Select the maximum number of bundles such that no courses overlap in any of the bundle.
Note: The ending of a range being the same as start of another isn't considered as an overlap.
Example 1:
Input:
N = 4
Bundles =
1 5
2 3
1 8
3 5
Output:
2
Explanation:
We can select 2 bundles at max while
staying true to the condition. For this,
we can pick the ranges (2,3) and (3,5)
without any overlap.
Example 2:
Input:
N = 5
Bundles =
7 9
2 8
1 3
10 11
10 16
Output:
3
Explanation:
We can pick the ranges (1,3),
(7,9) and (10,11) without any overlap.
Your Task:
You don't need to read input or print anything. Complete the function max_non_overlapping() that takes a 2D array representing N ranges as input parameter. Return the maximum number of course bundles.
Expected time complexity: O(NlogN)
Expected space complexity: O(1)
Constraints:
1 <= N <= 1000
0 <= range[i][j] <= 1000
|
class Solution:
def max_non_overlapping(self, ranges):
n = len(ranges)
if n <= 1:
return n
ranges.sort(key=lambda ranges: ranges[0])
end = ranges[0][1]
max = 1
for i in range(n):
if ranges[i][0] < end:
end = min(end, ranges[i][1])
else:
max += 1
end = ranges[i][1]
return max
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
def trailingZeroes(n):
cnt = 0
while n > 0:
n = int(n / 5)
cnt += n
return cnt
def binarySearch(n):
low = 0
high = 1000000.0
while low < high:
mid = int((low + high) / 2)
count = trailingZeroes(mid)
if count < n:
low = mid + 1
else:
high = mid
result = 0
while trailingZeroes(low) == n:
result += 1
low += 1
return result
class Solution:
def countZeroes(self, n):
return binarySearch(n)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def number_of_zeroes(self, n):
res = 0
value = 5
while value <= n:
res += n // value
value *= 5
return res
def countZeroes(self, n):
low = 0
high = 5 * n
while low < high:
mid = (low + high) // 2
noz = self.number_of_zeroes(mid)
if noz < n:
low = mid + 1
else:
high = mid
ans = 0
while self.number_of_zeroes(low) == n:
ans += 1
low += 1
return ans
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def count_fives(self, num):
result = 0
i = 5
while num // i > 0:
result += num // i
i *= 5
return result
def countZeroes(self, n):
l = 0
r = n * 5
while l <= r:
mid = (l + r) // 2
cnt = self.count_fives(mid)
if cnt == n:
return 5
if cnt > n:
r = mid - 1
else:
l = mid + 1
return 0
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def countZeroes(self, n):
smallestnumwithatleastnzeros = self.Helper(n)
smallestnumwithatleastnplusonezeros = self.Helper(n + 1)
return smallestnumwithatleastnplusonezeros - smallestnumwithatleastnzeros
def Helper(self, n):
low = 0
high = 5 * n
while low <= high:
mid = low + (high - low) // 2
if self.check(mid, n):
high = mid - 1
else:
low = mid + 1
return low
def check(self, val, n):
count = 0
f = 5
while f <= val:
count += val // f
f = f * 5
if count >= n:
return True
else:
return False
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def count(self, a):
c = 0
while a:
a = a // 5
c += a
return c
def solve(self, n):
i = 1
e = 5 * n
ans = 0
while i <= e:
mid = (i + e) // 2
if self.count(mid) >= n:
ans = mid
e = mid - 1
else:
i = mid + 1
return ans
def countZeroes(self, n):
return self.solve(n + 1) - self.solve(n)
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def countZeroes(self, n):
if n == 1:
return 5
count = 0
def zerocount(k):
zc = 0
while k != 0:
k = k // 5
zc += k
return zc
low = 0
high = 1000000.0
while low < high:
mid = (low + high) // 2
zcm = zerocount(mid)
if zcm >= n:
high = mid
else:
low = mid + 1
if zcm == n:
return 5
return 0
|
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
def zero_cnt(a):
i = 5
cnt = 0
while a >= i:
cnt += a // i
i *= 5
return cnt
class Solution:
def countZeroes(self, n):
i = 0
j = 100000000
while i <= j:
mid = (i + j) // 2
if zero_cnt(mid) == n:
return 5
elif zero_cnt(mid) < n:
i = mid + 1
else:
j = mid - 1
return 0
if __name__ == "__main__":
ob = Solution()
t = int(input())
for _ in range(t):
N = int(input())
ans = ob.countZeroes(N)
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def trailing_zeros(self, n):
num = 1
res = 0
while num:
ans = 0
i = 1
power = 5**i
while power <= num:
ans += num // power
i += 1
power = 5**i
if ans == n:
res += 1
elif ans > n:
break
num += 1
return res
def countZeroes(self, n):
return self.trailing_zeros(n)
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def cal(self, n):
count = 0
i = 5
while True:
if n // i >= 1:
count = count + n // i
i = i * 5
else:
break
return count
def countZeroes(self, n):
obj = Solution()
low = 1
high = n * 5
ans = 0
while low <= high:
mid = low + (high - low) // 2
temp = obj.cal(mid)
if temp == n:
ans = mid
break
elif temp > n:
high = mid - 1
else:
low = mid + 1
if ans == 0:
return 0
return 5
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER
|
Given an integer n, find the number of positive integers whose factorial ends with n zeros.
Example 1:
Input:
N = 1
Output: 5
Explanation:
5! = 120, 6! = 720, 7! = 5040,
8! = 40320 and 9! = 362880.
Example 2:
Input:
N = 5
Output: 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeroes() which takes the integer N as input parameters and returns the count of positive numbers whose factorial ends with N zeros.
Expected Time Complexity: O(log(n))
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=1000
|
class Solution:
def countZeroes(self, n):
low = 1
high = 1000000.0
result = 0
while low <= high:
mid = int(low + (high - low) / 2)
trailZeroes = self.trailingZeroes(mid)
if trailZeroes == n:
result = 5
high = mid - 1
elif trailZeroes < n:
low = mid + 1
else:
high = mid - 1
return result
def trailingZeroes(self, n):
cnt = 0
while n > 0:
n = int(n / 5)
cnt += n
return cnt
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
entry_i, exit_i = 0, 0
max_guest = [0, 0]
cnt = 0
while entry_i < N:
if exit_i == N or Entry[entry_i] <= Exit[exit_i]:
cnt += 1
if cnt > max_guest[0]:
max_guest[0] = cnt
max_guest[1] = Entry[entry_i]
entry_i += 1
else:
cnt -= 1
exit_i += 1
return max_guest
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
res = []
Entry.sort()
Exit.sort()
guest = 1
max_gst = 1
time = Entry[0]
i = 1
j = 0
while i < N and j < N:
if Entry[i] <= Exit[j]:
guest += 1
if guest > max_gst:
max_gst = guest
time = Entry[i]
i += 1
else:
guest -= 1
j += 1
res.append(max_gst)
res.append(time)
return res
|
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
maxEntry = max(Entry)
maxExit = max(Exit)
count = [0] * (max(maxEntry, maxExit) + 2)
for i in range(len(Entry)):
count[Entry[i]] += 1
count[Exit[i] + 1] -= 1
maxGuests, maxGuestsAt = -1, 0
curGuests = 0
for i in range(len(count)):
curGuests += count[i]
if curGuests > maxGuests:
maxGuests = curGuests
maxGuestsAt = i
return [maxGuests, maxGuestsAt]
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
A = [(v, 1) for v in Entry]
A.extend([(v + 1, -1) for v in Exit])
A.sort()
curtm, hc, mxhc, mntm = 0, 0, 0, 0
for tm, off in A:
if tm > curtm:
if hc > mxhc:
mxhc = hc
mntm = curtm
curtm = tm
hc += off
if hc > mxhc:
mxhc = hc
mntm = curtm
return mxhc, mntm
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
i = 0
j = 0
time = 0
maxi = 0
count = 0
while i < N and j < N:
if Entry[i] <= Exit[j]:
count += 1
if count > maxi:
maxi = count
time = Entry[i]
i += 1
else:
count -= 1
j += 1
return [maxi, time]
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
maxi = float("-inf")
Entry.sort()
Exit.sort()
guest = 0
p1 = 0
p2 = 0
while p1 < len(Entry):
if Entry[p1] <= Exit[p2]:
guest += 1
if guest > maxi:
maxi = guest
time = Entry[p1]
p1 += 1
else:
guest -= 1
p2 += 1
return maxi, time
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
h = [0] * (max(exit) + 2)
for i in range(N):
h[Entry[i]] += 1
h[Exit[i] + 1] -= 1
curr = 0
ans = 0, -1
for i in range(max(exit) + 1):
curr += h[i]
h[i] = curr
if h[i] > ans[0]:
ans = h[i], i
return ans
|
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
mx = max(max(Entry), max(Exit))
arr = [0] * (mx + 2)
for i in range(N):
arr[Entry[i]] += 1
arr[Exit[i] + 1] -= 1
curr = 0
ans = float("-inf")
for i in range(len(arr)):
curr += arr[i]
if curr > ans:
ans = curr
res = ans, i
return res
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
guestsIn, maxGuests, maxGuestsAt = 1, 1, Entry[0]
i, j = 1, 0
while i < len(Entry) and j < len(Exit):
if Entry[i] <= Exit[j]:
guestsIn += 1
if guestsIn > maxGuests:
maxGuests = guestsIn
maxGuestsAt = Entry[i]
i += 1
else:
guestsIn -= 1
j += 1
return [maxGuests, maxGuestsAt]
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
{1, 2, 5, 5, 10}
{4, 5, 9, 12, 12}
Entry.sort()
Exit.sort()
ent, ex = 0, 0
time, maxGuest = 0, 0
curGuest = 0
while ent < N:
if Entry[ent] <= Exit[ex]:
curGuest += 1
if maxGuest < curGuest:
maxGuest = curGuest
time = Entry[ent]
ent += 1
else:
curGuest -= 1
ex += 1
return maxGuest, time
|
CLASS_DEF FUNC_DEF EXPR NUMBER NUMBER NUMBER NUMBER NUMBER EXPR NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
max_guests = 0
c_time = -1
temp_entry = Entry
temp_entry.sort()
Exit.sort()
k = i = 0
temp = 0
while i < N:
if temp_entry[i] <= Exit[k]:
temp += 1
if temp > max_guests:
max_guests = temp
c_time = temp_entry[i]
i += 1
else:
k += 1
temp -= 1
return max_guests, c_time
if __name__ == "__main__":
t = int(input())
for _ in range(t):
N = int(input())
entry = [int(x) for x in input().split()]
exit = [int(x) for x in input().split()]
solObj = Solution()
ans = solObj.findMaxGuests(entry, exit, N)
print(ans[0], ans[1])
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry = sorted(Entry)
Exit = sorted(Exit)
i = 0
j = 0
maxi = 0
addi = 0
index = 0
while i < N and j < N:
en = Entry[i]
dep = Exit[j]
if en <= dep:
addi += 1
i += 1
if dep < en:
addi -= 1
j += 1
if addi > maxi:
maxi = addi
index = Entry[i - 1]
return maxi, index
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, n):
end = max(Exit) + 3
count = [0] * end
for i in range(n):
count[Entry[i]] += 1
count[Exit[i] + 1] -= 1
max_ocrr = float("-inf")
ans = 0
for i in range(1, end):
count[i] += count[i - 1]
if count[i] > max_ocrr:
max_ocrr = count[i]
ans = i
return [max_ocrr, ans]
|
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
ans, f = 0, 0
j = 0
for i in range(N):
while Exit[j] < Entry[i]:
j += 1
d = i + 1 - j
if d > f:
f = d
ans = Entry[i]
return [f, ans]
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
lb = Entry
lp = Exit
lb.sort()
lp.sort()
lb.reverse()
lp.reverse()
i = len(lb) - 1
c = len(lp) - 1
soma = 0
max = -1
p = 0
while i >= 0 and c >= 0:
m = min(lb[i], lp[c])
clb = 0
while i >= 0 and lb[i] == m:
clb += 1
i -= 1
clp = 0
while c >= 0 and lp[c] == m:
clp += 1
c -= 1
soma += clb
if soma > max:
max = soma
p = m
soma -= clp
return max, p
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
guests = []
for i in range(N):
guests.append([Entry[i], False])
guests.append([Exit[i], True])
guests.sort()
maxgst = -1
attgst = 0
tmpgst = 0
for i in range(len(guests)):
if not guests[i][1]:
attgst += 1
else:
attgst -= 1
if attgst > maxgst:
maxgst = attgst
tmpgst = guests[i][0]
return maxgst, tmpgst
if __name__ == "__main__":
t = int(input())
for _ in range(t):
N = int(input())
entry = [int(x) for x in input().split()]
exit = [int(x) for x in input().split()]
solObj = Solution()
ans = solObj.findMaxGuests(entry, exit, N)
print(ans[0], ans[1])
|
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, arrl, exit, n):
arrl.sort()
exit.sort()
guests_in = 1
max_guests = 1
time = arrl[0]
i = 1
j = 0
while i < n and j < n:
if arrl[i] <= exit[j]:
guests_in = guests_in + 1
if guests_in > max_guests:
max_guests = guests_in
time = arrl[i]
i = i + 1
else:
guests_in = guests_in - 1
j = j + 1
return max_guests, time
if __name__ == "__main__":
t = int(input())
for _ in range(t):
N = int(input())
entry = [int(x) for x in input().split()]
exit = [int(x) for x in input().split()]
solObj = Solution()
ans = solObj.findMaxGuests(entry, exit, N)
print(ans[0], ans[1])
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, entry, exit, n):
maxi = max(exit)
arr = [0] * (maxi + 2)
for i in range(n):
arr[entry[i]] += 1
arr[exit[i] + 1] += -1
prefix = arr[0]
for i in range(1, len(arr)):
prefix += arr[i]
arr[i] = prefix
ind = 0
maxi = arr[0]
for i in range(1, len(arr)):
if arr[i] > maxi:
maxi = arr[i]
ind = i
return [maxi, ind]
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
max_g = 0, 0
count = 0
i, j = 0, 0
while i < len(Entry):
if j >= len(Exit) or Entry[i] <= Exit[j]:
count += 1
if max_g[0] < count:
max_g = count, Entry[i]
i += 1
else:
count -= 1
j += 1
if j == len(Exit):
i += 1
return max_g
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
i = 0
j = 0
p = 0
t = 0
m = 0
arr = []
while i < len(Exit) and i >= j:
l = i
if Entry[i] <= Exit[j]:
p += 1
i += 1
else:
p -= 1
j += 1
if m < p:
m = p
t = Entry[l]
return [m, t]
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
ans = 0
count = 0
data = []
time = 0
for i in range(N):
data.append([Entry[i], "x"])
data.append([Exit[i], "y"])
data = sorted(data)
for i in range(len(data)):
if data[i][1] == "x":
count += 1
if data[i][1] == "y":
count -= 1
if ans < count:
ans = count
time = data[i][0]
return ans, time
|
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
if len(Exit) == 1:
return [1, Entry[0]]
Entry.sort(reverse=False)
Exit.sort(reverse=False)
i = 0
j = 0
maxcount = float("-inf")
count = 0
while i < len(Entry):
if Entry[i] <= Exit[j]:
count += 1
if count > maxcount:
maxcount = count
time = Entry[i]
i += 1
else:
count -= 1
j += 1
return [maxcount, time]
|
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, start, end, N):
m1 = max(start)
m2 = max(end)
arr = [(0) for i in range(max(m1, m2) + 2)]
for i in start:
arr[i] += 1
for j in end:
arr[j + 1] += -1
c = 0
ms = 0
time = 0
for i in range(len(arr)):
c += arr[i]
if c > ms:
ms = c
time = i
return [ms, time]
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
ent = sorted(Entry)
exit = sorted(Exit)
i = 1
j = 0
curr = 1
res = 1
min_time = ent[0]
li = []
while i < N and j < N:
if ent[i] <= exit[j]:
curr += 1
i += 1
else:
curr -= 1
j += 1
if res < curr:
res = curr
min_time = ent[i - 1]
li.append(res)
li.append(min_time)
return li
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
cou = 1
ma = 1
time = Entry[0]
i = 1
j = 0
while i < N and j < N:
if Exit[j] >= Entry[i]:
cou = cou + 1
if ma < cou:
ma = cou
time = Entry[i]
i = i + 1
else:
cou = cou - 1
j = j + 1
return [ma, time]
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
total = Entry + Exit
entry = [[e, "A"] for e in Entry]
exit = [[e, "B"] for e in Exit]
total = entry + exit
total.sort()
c = 0
m = 0
t = -1
for i in range(len(total)):
if total[i][1] == "A":
c = c + 1
if c > m:
m = c
t = total[i][0]
else:
c = c - 1
return m, t
|
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR STRING VAR VAR ASSIGN VAR LIST VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
l = []
for i in range(N):
l.append([Entry[i], 0])
l.append([Exit[i], 1])
l.sort()
c = 0
m = 0
for i in l:
if i[1] == 0:
c += 1
else:
c -= 1
if c > m:
m = c
a = i[0]
return [m, a]
|
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
d = {}
for i in range(N):
if Entry[i] not in d:
d[Entry[i]] = 1
else:
d[Entry[i]] += 1
if Exit[i] + 1 not in d:
d[Exit[i] + 1] = -1
else:
d[Exit[i] + 1] -= 1
key = sorted(d)
for i in range(1, len(key)):
d[key[i]] += d[key[i - 1]]
maxi = -1
for k in key:
if d[k] > maxi:
maxi = d[k]
ans = [d[k], k]
return ans
|
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR RETURN VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
dp = [0] * int(100000.0 + 2)
for i in range(N):
dp[Entry[i]] += 1
dp[Exit[i] + 1] -= 1
c = 0
t = 0
for i in range(1, len(dp)):
dp[i] += dp[i - 1]
if c < dp[i]:
c = dp[i]
t = i
return [c, t]
|
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN LIST VAR VAR
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
i, j = 0, 0
count = 0
max_g = 0, 0
while i < len(Entry) and j <= len(Exit):
if j == len(Exit) or Entry[i] <= Exit[j]:
count += 1
if count > max_g[0]:
max_g = count, Entry[i]
i += 1
else:
count -= 1
j += 1
return max_g
if __name__ == "__main__":
t = int(input())
for _ in range(t):
N = int(input())
entry = [int(x) for x in input().split()]
exit = [int(x) for x in input().split()]
solObj = Solution()
ans = solObj.findMaxGuests(entry, exit, N)
print(ans[0], ans[1])
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were
guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were
all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}
|
class Solution:
def findMaxGuests(self, Entry, Exit, N):
Entry.sort()
Exit.sort()
count = 0
maxi = 0
time = 0
j = 0
for i in range(N):
count += 1
if count > maxi:
maxi = count
time = Entry[i]
while j < N and i < N - 1 and Exit[j] < Entry[i + 1]:
count -= 1
j += 1
return maxi, time
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
|
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
|
t = int(input())
for _ in range(t):
n = int(input())
nums = []
for i in range(2 * n - 1):
a, b = map(int, input().split())
nums.append([b, a, i + 1])
nums = sorted(nums)[::-1]
vals = [nums[0][2]]
i = 1
while i + 1 < len(nums):
c = i
if nums[i][1] < nums[i + 1][1]:
c = i + 1
vals.append(nums[c][2])
i += 2
print("YES")
print(*vals)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
|
t = int(input())
while t:
t = t - 1
boxes = []
n = int(input())
num_box = 2 * n - 1
for i in range(num_box):
pair = input().split()
apples = int(pair[0])
oranges = int(pair[1])
boxes.append((apples, oranges, i + 1))
print("YES")
boxes.sort(reverse=True)
orange_boxes = list(zip(*boxes))[1]
total_oranges = sum(orange_boxes)
half_sum1 = sum(orange_boxes[::2])
half_sum2 = sum(orange_boxes[1::2])
index_list = list(list(zip(*boxes))[2])
index_list1 = index_list[::2]
index_list2 = index_list[1::2]
index_list2.append(index_list1[0])
if half_sum1 >= half_sum2:
print(*index_list1, sep=" ")
else:
print(*index_list2, sep=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING
|
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
|
import sys
input = sys.stdin.readline
t = int(input())
for cs in range(t):
n = int(input())
arr = []
for i in range(2 * n - 1):
a, b = map(int, input().split())
arr.append((a, b, i))
arr.sort()
res = []
for i in range(0, len(arr), 2):
if i + 1 < len(arr):
if arr[i][1] > arr[i + 1][1]:
res.append(arr[i][2] + 1)
else:
res.append(arr[i + 1][2] + 1)
else:
res.append(arr[i][2] + 1)
print("YES")
print(" ".join(map(str, res)))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
A famous casino is suddenly faced with a sharp decline of their revenues. They decide to offer Texas hold'em also online. Can you help them by writing an algorithm that can rank poker hands?
Task:
Create a poker hand that has a constructor that accepts a string containing 5 cards:
```python
hand = PokerHand("KS 2H 5C JD TD")
```
The characteristics of the string of cards are:
A space is used as card seperator
Each card consists of two characters
The first character is the value of the card, valid characters are:
`2, 3, 4, 5, 6, 7, 8, 9, T(en), J(ack), Q(ueen), K(ing), A(ce)`
The second character represents the suit, valid characters are:
`S(pades), H(earts), D(iamonds), C(lubs)`
The poker hands must be sortable by rank, the highest rank first:
```python
hands = []
hands.append(PokerHand("KS 2H 5C JD TD"))
hands.append(PokerHand("2C 3C AC 4C 5C"))
hands.sort() (or sorted(hands))
```
Apply the Texas Hold'em rules for ranking the cards.
There is no ranking for the suits.
An ace can either rank high or rank low in a straight or straight flush. Example of a straight with a low ace:
`"5C 4D 3C 2S AS"`
Note: there are around 25000 random tests, so keep an eye on performances.
|
class PokerHand(object):
VALUES = "A23456789TJQKA"
def __repr__(self):
return self.hand
def __init__(self, hand):
self.hand = hand
values = "".join(sorted(hand[::3], key=self.VALUES[1:].index))
suits = set(hand[1::3])
hi_straight = values in self.VALUES
lo_straight = values[-1] + values[:-1] in self.VALUES
is_flush = len(suits) == 1
self.score = 2 * sum(values.count(card) for card in values) + 13 * (
hi_straight or lo_straight
) + 15 * is_flush, [
(
self.VALUES[:-1].index(card)
if lo_straight
else self.VALUES[1:].index(card)
)
for card in values[::-1]
]
def __lt__(self, other):
return other.score < self.score
|
CLASS_DEF VAR ASSIGN VAR STRING FUNC_DEF RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF RETURN VAR VAR
|
A famous casino is suddenly faced with a sharp decline of their revenues. They decide to offer Texas hold'em also online. Can you help them by writing an algorithm that can rank poker hands?
Task:
Create a poker hand that has a constructor that accepts a string containing 5 cards:
```python
hand = PokerHand("KS 2H 5C JD TD")
```
The characteristics of the string of cards are:
A space is used as card seperator
Each card consists of two characters
The first character is the value of the card, valid characters are:
`2, 3, 4, 5, 6, 7, 8, 9, T(en), J(ack), Q(ueen), K(ing), A(ce)`
The second character represents the suit, valid characters are:
`S(pades), H(earts), D(iamonds), C(lubs)`
The poker hands must be sortable by rank, the highest rank first:
```python
hands = []
hands.append(PokerHand("KS 2H 5C JD TD"))
hands.append(PokerHand("2C 3C AC 4C 5C"))
hands.sort() (or sorted(hands))
```
Apply the Texas Hold'em rules for ranking the cards.
There is no ranking for the suits.
An ace can either rank high or rank low in a straight or straight flush. Example of a straight with a low ace:
`"5C 4D 3C 2S AS"`
Note: there are around 25000 random tests, so keep an eye on performances.
|
class PokerHand(object):
CARD = "23456789TJQKA"
def __repr__(self):
return str(self.hand)
def __init__(self, hand):
self.hand = hand
values = "".join(sorted(hand[::3], key=self.CARD.index))
suits = set(hand[1::3])
is_straight = values in self.CARD or values == "2345A"
is_flush = len(suits) == 1
self.score = 2 * sum(
values.count(card) for card in values
) + 13 * is_straight + 15 * is_flush, [
self.CARD.index(card) for card in values[::-1]
]
if values == "2345A":
self.score = 13 * is_straight + 15 * is_flush + 10, [3, 2, 1, 0, 12]
def __lt__(self, other):
return self.score > other.score
|
CLASS_DEF VAR ASSIGN VAR STRING FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR VAR
|
A famous casino is suddenly faced with a sharp decline of their revenues. They decide to offer Texas hold'em also online. Can you help them by writing an algorithm that can rank poker hands?
Task:
Create a poker hand that has a constructor that accepts a string containing 5 cards:
```python
hand = PokerHand("KS 2H 5C JD TD")
```
The characteristics of the string of cards are:
A space is used as card seperator
Each card consists of two characters
The first character is the value of the card, valid characters are:
`2, 3, 4, 5, 6, 7, 8, 9, T(en), J(ack), Q(ueen), K(ing), A(ce)`
The second character represents the suit, valid characters are:
`S(pades), H(earts), D(iamonds), C(lubs)`
The poker hands must be sortable by rank, the highest rank first:
```python
hands = []
hands.append(PokerHand("KS 2H 5C JD TD"))
hands.append(PokerHand("2C 3C AC 4C 5C"))
hands.sort() (or sorted(hands))
```
Apply the Texas Hold'em rules for ranking the cards.
There is no ranking for the suits.
An ace can either rank high or rank low in a straight or straight flush. Example of a straight with a low ace:
`"5C 4D 3C 2S AS"`
Note: there are around 25000 random tests, so keep an eye on performances.
|
class PokerHand(object):
CARD = "23456789TJQKA"
RESULT = ["Loss", "Tie", "Win"]
def __repr__(self):
return self.hand
def __lt__(self, other):
res = self.compare_with(other)
return res == self.RESULT[2]
def __init__(self, hand):
self.hand = hand
values = "".join(sorted(hand[::3], key=self.CARD.index))
suits = set(hand[1::3])
is_straight = values in self.CARD
is_straight_bad = values in ["2JQKA", "23QKA", "234KA", "2345A"]
is_flush = len(suits) == 1
self.score = 2 * sum(
values.count(card) for card in values
) + 13 * is_straight + 12.5 * is_straight_bad + 15 * is_flush, [
self.CARD.index(card) for card in values[::-1]
]
def compare_with(self, other):
return self.RESULT[(self.score > other.score) - (self.score < other.score) + 1]
|
CLASS_DEF VAR ASSIGN VAR STRING ASSIGN VAR LIST STRING STRING STRING FUNC_DEF RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF RETURN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER
|
A famous casino is suddenly faced with a sharp decline of their revenues. They decide to offer Texas hold'em also online. Can you help them by writing an algorithm that can rank poker hands?
Task:
Create a poker hand that has a constructor that accepts a string containing 5 cards:
```python
hand = PokerHand("KS 2H 5C JD TD")
```
The characteristics of the string of cards are:
A space is used as card seperator
Each card consists of two characters
The first character is the value of the card, valid characters are:
`2, 3, 4, 5, 6, 7, 8, 9, T(en), J(ack), Q(ueen), K(ing), A(ce)`
The second character represents the suit, valid characters are:
`S(pades), H(earts), D(iamonds), C(lubs)`
The poker hands must be sortable by rank, the highest rank first:
```python
hands = []
hands.append(PokerHand("KS 2H 5C JD TD"))
hands.append(PokerHand("2C 3C AC 4C 5C"))
hands.sort() (or sorted(hands))
```
Apply the Texas Hold'em rules for ranking the cards.
There is no ranking for the suits.
An ace can either rank high or rank low in a straight or straight flush. Example of a straight with a low ace:
`"5C 4D 3C 2S AS"`
Note: there are around 25000 random tests, so keep an eye on performances.
|
class PokerHand(object):
def __init__(self, hand):
self.hand = hand
self.hand_value = self.value(hand)
def __repr__(self):
return self.hand
def __lt__(self, other):
return self.hand_value > other.hand_value
def __eq__(self, other):
return self.hand_value == other.hand_value
def compare_with(self, other):
if self.hand_value > other.hand_value:
return "Win"
elif self.hand_value < other.hand_value:
return "Loss"
elif self.hand_value == other.hand_value:
return "Tie"
@staticmethod
def hand_to_vector(hand):
vec_hand = [0] * 13
for card in hand.split():
try:
vec_hand[int(card[0]) - 2] += 1
except:
switcher = {"A": 12, "K": 11, "Q": 10, "J": 9, "T": 8}
vec_hand[switcher[card[0]]] += 1
return vec_hand
@staticmethod
def combination(hand):
vec_hand = PokerHand.hand_to_vector(hand)
suited = False
if 1 == len(set([x[1] for x in hand.split()])):
suited = True
if 4 in vec_hand:
return "Four of a kind"
elif 3 in vec_hand:
if 2 in vec_hand:
return "Full house"
else:
return "Three of a kind"
else:
if 2 in vec_hand:
if 2 == vec_hand.count(2):
return "Two pair"
else:
return "One pair"
if "11111" not in "".join([str(x) for x in vec_hand[-1:] + vec_hand]):
if suited:
return "Flush"
else:
return "High card"
elif not suited:
return "Straight"
elif vec_hand[8] == 1 and vec_hand[12] == 1:
return "Royal flush"
else:
return "Straight flush"
@staticmethod
def value(hand):
hand_vec = PokerHand.hand_to_vector(hand)
value_vec = [
"0",
"0000",
"0000",
"0000",
"0",
"0",
"0000",
"0000",
"0000",
"0000",
]
combination = PokerHand.combination(hand)
if combination == "One pair":
value_vec[9] = "{:04b}".format(hand_vec.index(2))
elif combination == "Two pair":
value_vec[8] = "{:04b}".format(hand_vec.index(2))
value_vec[7] = "{:04b}".format(hand_vec.index(2, hand_vec.index(2) + 1))
elif combination == "Three of a kind":
value_vec[6] = "{:04b}".format(hand_vec.index(3))
elif combination == "Straight":
value_vec[5] = "1"
if hand_vec[12] == 1 and hand_vec[3] == 1:
hand_vec[12] = 0
elif combination == "Flush":
value_vec[4] = "1"
elif combination == "Full house":
value_vec[3] = "{:04b}".format(hand_vec.index(2))
value_vec[2] = "{:04b}".format(hand_vec.index(3))
elif combination == "Four of a kind":
value_vec[1] = "{:04b}".format(hand_vec.index(4))
elif combination == "Straight flush":
value_vec[0] = "1"
if hand_vec[12] == 1 and hand_vec[3] == 1:
hand_vec[12] = 0
elif combination == "Royal flush":
value_vec[0] = "1"
value_vec[1] = "1111"
return int(
"".join(value_vec)
+ "".join(
reversed(list([(str(x) if x == 1 else str(0)) for x in hand_vec]))
),
2,
)
|
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN STRING IF VAR VAR RETURN STRING IF VAR VAR RETURN STRING FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER VAR VAR VAR NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF NUMBER VAR RETURN STRING IF NUMBER VAR IF NUMBER VAR RETURN STRING RETURN STRING IF NUMBER VAR IF NUMBER FUNC_CALL VAR NUMBER RETURN STRING RETURN STRING IF STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR RETURN STRING RETURN STRING IF VAR RETURN STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN STRING RETURN STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR NUMBER STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING RETURN FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
a = input().split(" ")
x1 = int(a[0])
x2 = int(a[1])
coor1 = []
coor2 = []
eps = 1e-09
for i in range(n):
a = input().split(" ")
k = int(a[0])
b = int(a[1])
coor1.append((k * (x1 + eps) + b, i))
coor2.append((k * (x2 - eps) + b, i))
coor1.sort()
coor2.sort()
s = "NO"
for i in range(len(coor1)):
if coor1[i][1] != coor2[i][1]:
s = "YES"
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
def byfirst(a):
return a[0]
n = int(input())
x1, x2 = [int(i) for i in input().split()]
a = {}
for i in range(n):
k, b = [int(i) for i in input().split()]
x, y = k * x1 + b, k * x2 + b
if x in a:
a[x] += [y]
else:
a[x] = [y]
b = list(a.keys())
b.sort()
m = max(a[b[0]])
flag = 0
for i in b[1:]:
if m > min(a[i]):
flag = 1
break
else:
m = max(a[i])
if flag:
print("YES")
else:
print("NO")
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR LIST VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
import sys
input = sys.stdin.buffer.readline
n = int(input())
l, r = map(int, input().split())
ly = []
ry = []
for i in range(n):
k, m = map(int, input().split())
ly.append([k * (l + 10**-8) + m, i])
ry.append([k * (r - 10**-8) + m, i])
ly.sort(key=lambda x: (x[0], x[1]))
ry.sort(key=lambda x: (x[0], x[1]))
for i in range(n):
if ly[i][1] != ry[i][1]:
print("YES")
break
else:
print("NO")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
def main():
n = int(input())
x1, x2 = map(int, input().split())
res = []
for _ in range(n):
k, b = map(int, input().split())
res.append((k * x1 + b, k * x2 + b))
res.sort()
print(("NO", "YES")[any(y1[1] > y2[1] for y1, y2 in zip(res, res[1:]))])
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
from sys import stdin
n = int(stdin.readline())
x1, x2 = map(int, stdin.readline().split())
ys = []
for i in range(n):
m, b = map(int, stdin.readline().split())
ys.append([x1 * m + b, x2 * m + b])
ys.sort()
intersect = False
for i in range(1, n):
if ys[i - 1][1] > ys[i][1]:
intersect = True
if intersect:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
def rline():
return [int(i) for i in input().split()]
N = int(input())
L, R = rline()
l = [rline() for i in range(N)]
atL = []
atR = []
for i in range(N):
k, b = l[i]
atL.append((k * L + b, k, i))
atR.append((k * R + b, -k, i))
atL.sort()
atR.sort()
atL = [i[2] for i in atL]
atR = [i[2] for i in atR]
print(["YES", "NO"][atL == atR])
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
ertekek = []
n = int(input())
x1, x2 = [int(i) for i in input().split()]
for i in range(n):
k, b = [int(i) for i in input().split()]
bal = k * x1 + b
jobb = k * x2 + b
ertekek.append([bal, jobb])
ertekek.sort()
szamlalo = 0
for i in range(len(ertekek) - 1):
if ertekek[i][0] < ertekek[i + 1][0] and ertekek[i][1] > ertekek[i + 1][1]:
szamlalo += 1
if szamlalo > 0:
print("YES")
else:
print("NO")
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
points = []
flag = False
x1, x2 = map(int, input().split())
for i in range(n):
a, b = map(int, input().split())
points.append((a, b))
p = []
for i in range(n):
p.append((points[i][0] * x1 + points[i][1], points[i][0] * x2 + points[i][1]))
p.sort()
for i in range(n - 1):
if p[i][0] != p[i + 1][0]:
if p[i][1] > p[i + 1][1]:
flag = True
if flag:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
X, Y = input().split()
X, Y = float(X) + 1e-10, float(Y) - 1e-10
L = [list(map(float, input().split())) for _ in range(n)]
print(
"NO"
if [i for x, i in sorted((k * X + b, i) for i, (k, b) in enumerate(L))]
== [i for x, i in sorted((k * Y + b, i) for i, (k, b) in enumerate(L))]
else "YES"
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR STRING STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
b = [(0) for i in range(n)]
k = [(0) for i in range(n)]
x1, x2 = (int(x) for x in input().split())
for i in range(n):
k[i], b[i] = (int(x) for x in input().split())
y1 = [(x1 * k[i] + b[i]) for i in range(n)]
y2 = [(x2 * k[i] + b[i]) for i in range(n)]
y3 = [(y1[i], y2[i], i) for i in range(n)]
y3.sort()
r1 = [(0) for i in range(n)]
for i in range(n):
r1[y3[i][-1]] = i
y4 = [(y2[i], r1[i], i) for i in range(n)]
y4.sort()
r2 = [(0) for i in range(n)]
for i in range(n):
r2[y4[i][-1]] = i
ans = 0
for i in range(n):
if r1[i] < r2[i]:
ans = 1
break
if ans:
print("Yes")
else:
print("No")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
import sys
n = int(input())
x1, x2 = [int(tmp) for tmp in input().split()]
k = []
b = []
kek = 0
lel = 0
for i in range(n):
tmpk, tmpb = [int(tmp) for tmp in input().split()]
k.append(tmpk)
b.append(tmpb)
up = [([0] * 3) for i in range(n)]
down = [([0] * 3) for i in range(n)]
for i in range(n):
up[i][0] = k[i] * x1 + b[i]
up[i][1] = k[i] * x2 + b[i]
up[i][2] = i
down[i][0] = k[i] * x2 + b[i]
down[i][1] = k[i] * x1 + b[i]
down[i][2] = i
up.sort()
down.sort()
for i in range(n):
if up[i][2] != down[i][2]:
print("yes")
sys.exit()
print("no")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
def cross(l1, l2, x2):
return l2[0] * x2 + l2[1] < l1[0] * x2 + l1[1]
def __starting_point():
n = int(input())
x1, x2 = list(map(int, input().split()))
data = [tuple(map(int, input().split())) for i in range(n)]
data = list(sorted(data, key=lambda x: (x[0] * x1 + x[1], x[0] * x2 + x[1])))
for i in range(len(data) - 1):
if cross(data[i], data[i + 1], x2):
print("YES")
return
print("NO")
__starting_point()
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
eps = 1e-09
x1, x2 = [int(i) for i in input().split()]
x1 += eps
x2 -= eps
area1 = []
area2 = []
for i in range(n):
k, b = [int(i) for i in input().split()]
y1 = x1 * k + b
y2 = x2 * k + b
area1.append([y1, i])
area2.append([y2, i])
area1.sort(key=lambda a: a[0])
area2.sort(key=lambda a: a[0])
yep = False
l = len(area1)
for i in range(l):
if area1[i][1] != area2[i][1]:
yep = True
break
if yep:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
x1, x2 = map(int, input().split())
k, b = [], []
for _ in range(n):
kk, bb = map(int, input().split())
k.append(kk)
b.append(bb)
at1 = sorted(range(n), key=lambda i: k[i] * (x1 + 1e-08) + b[i])
at2 = sorted(range(n), key=lambda i: k[i] * (x2 - 1e-08) + b[i])
print(["YES", "NO"][at1 == at2])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
x, y = map(int, input().split())
u, v = [], []
x += 1e-07
y -= 1e-07
for i in range(n):
k, m = map(int, input().split())
u += [(k * x + m, i)]
v += [(k * y + m, i)]
u, v = sorted(u), sorted(v)
for i in range(n):
if u[i][1] != v[i][1]:
print("YES")
break
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST BIN_OP BIN_OP VAR VAR VAR VAR VAR LIST BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
x1, x2 = map(int, input().split())
x1 += 10**-8
x2 -= 10**-8
lines = []
for i in range(n):
lines.append(list(map(int, input().split())))
ord_left = []
ord_right = []
for i in range(n):
ord_left.append(lines[i][0] * x1 + lines[i][1])
ord_right.append(lines[i][0] * x2 + lines[i][1])
enum_l = list(range(n))
enum_r = list(range(n))
enum_l.sort(key=lambda ord: ord_left[ord])
enum_r.sort(key=lambda ord: ord_right[ord])
if enum_l == enum_r:
print("NO")
else:
print("YES")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
l, r = map(int, input().split())
i = 0
s = []
while i < n:
k, b = map(int, input().split())
s.append([l * k + b, r * k + b])
i += 1
s.sort()
y = 0
i = 1
while i < n:
if s[i - 1][1] > s[i][1]:
y = 1
i += 1
print(["NO", "YES"][y])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
k = []
x = int(input())
c, d = list(map(int, input().split(" ")))
for i in range(x):
a, b = list(map(int, input().split(" ")))
k.append([c * a + b, d * a + b])
k.sort()
for i in range(len(k) - 1):
if k[i + 1][1] < k[i][1]:
print("YES")
quit()
print("NO")
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
a = list()
x1, x2 = map(int, input().split())
for i in range(n):
k, b = map(int, input().split())
y1 = k * x1 + b
y2 = k * x2 + b
a.append((y1, y2))
a.sort()
fl = "NO"
y1m = a[0][0]
y2m = a[0][1]
for y1, y2 in a:
if y2 < y2m:
fl = "YES"
else:
y2m = max(y2m, y2)
print(fl)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
a = []
n = int(input())
x1, x2 = map(int, input().split())
for i in range(n):
k, b = map(int, input().split())
c, d = k * x1 + b, k * x2 + b
a.append([c, d])
def f(a):
return a[1]
a.sort()
for i in range(1, len(a)):
if a[i][0] > a[i - 1][0] and a[i][1] < a[i - 1][1]:
print("Yes")
quit()
print("No")
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
import sys
from sys import stdin, stdout
n = int(input())
x1, x2 = [int(x) for x in input().split()]
cuts = []
for i in range(n):
k, b = [int(x) for x in input().split()]
cuts.append([k * x1 + b, k * x2 + b])
res = sorted(cuts, key=lambda x: (x[0], x[1]))
max1_e = res[0][0]
max2_e = res[0][1]
ok = True
for i in range(1, len(res)):
prev = res[i - 1]
cur = res[i]
if cur[1] < max2_e:
stdout.write("YES\n")
ok = False
break
max2_e = max(max2_e, cur[1])
if ok:
stdout.write("NO\n")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
x1, x2 = map(int, input().split())
seg = []
for _ in range(0, n):
k, b = map(int, input().split())
y1 = k * x1 + b
y2 = k * x2 + b
seg.append((y1, y2))
seg.sort()
for i in range(1, n):
if seg[i][1] < seg[i - 1][1]:
print("Yes")
exit(0)
print("No")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
def equation(k, x, b):
return k * x + b
num = int(input())
ans = []
x1, x2 = map(int, input().split())
for i in range(0, num):
k, b = map(int, input().split())
ans.append((equation(k, x1, b), equation(k, x2, b)))
ans.sort()
for i in range(1, num):
if (
ans[i][0] > ans[i - 1][0]
and ans[i][1] < ans[i - 1][1]
or ans[i - 1][0] < ans[i][0]
and ans[i - 1][1] > ans[i][1]
):
print("YES")
exit()
print("NO")
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
|
n = int(input())
x1, x2 = list(map(float, input().split()))
x1 += 1e-10
x2 -= 1e-10
lines = [tuple(map(float, input().split())) for _ in range(n)]
l1 = sorted((k * x1 + b, i) for i, (k, b) in enumerate(lines))
l2 = sorted((k * x2 + b, i) for i, (k, b) in enumerate(lines))
if [i for x, i in l1] == [i for x, i in l2]:
print("NO")
else:
print("YES")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.