description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis. -----Input----- The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line. -----Output----- For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. -----Examples----- Input 2 ........ ........ ......#. K..##..# .......# ...##..# ......#. K....... ........ ........ ..#..... ..#..#.. ..####.. ...##... ........ ....K#K# Output YES NO -----Note----- Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
N = range(8) test = int(input()) for i_test in range(test): if i_test: input() x1, y1, x2, y2 = 0, 0, 0, 0 map = [input() for i in N] for i in N: for j in N: if map[i][j] == "K": x1, y1, x2, y2 = x2, y2, i, j if abs(x1 - x2) % 4 == 0 and abs(y1 - y2) % 4 == 0: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis. -----Input----- The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line. -----Output----- For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. -----Examples----- Input 2 ........ ........ ......#. K..##..# .......# ...##..# ......#. K....... ........ ........ ..#..... ..#..#.. ..####.. ...##... ........ ....K#K# Output YES NO -----Note----- Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
3 n = int(input()) for _ in range(n): k = [] b = [] for i in range(8): s = input() for j in range(8): if s[j] == "K": k.append((i, j)) print( "YES" if abs(k[0][0] - k[1][0]) % 4 == 0 and abs(k[0][1] - k[1][1]) % 4 == 0 else "NO" ) if _ < n - 1: input()
EXPR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER STRING STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis. -----Input----- The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line. -----Output----- For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. -----Examples----- Input 2 ........ ........ ......#. K..##..# .......# ...##..# ......#. K....... ........ ........ ..#..... ..#..#.. ..####.. ...##... ........ ....K#K# Output YES NO -----Note----- Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
t = int(input()) for k in range(t): r8 = range(8) a = [input() for i in r8] ij = [(i, j) for i in r8 for j in r8] x, y = ((i, j) for i, j in ij if a[i][j] == "K") def s(p): d = [ (p[0] - 2, p[1] - 2), (p[0] + 2, p[1] - 2), (p[0] - 2, p[1] + 2), (p[0] + 2, p[1] + 2), ] return set((i, j) for i, j in ij if (i, j) in d) print("YES" if len(s(x) & s(y)) > 0 else "NO") if k != t - 1: input()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR STRING FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER STRING STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis. -----Input----- The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line. -----Output----- For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. -----Examples----- Input 2 ........ ........ ......#. K..##..# .......# ...##..# ......#. K....... ........ ........ ..#..... ..#..#.. ..####.. ...##... ........ ....K#K# Output YES NO -----Note----- Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
MOVS = [(2, -2), (-2, 2), (-2, -2), (2, 2)] def check(a): return 0 <= a < 8 set1 = set() set2 = set() dic1 = dict() dic2 = dict() def cango1(matrix, pos, lap): for dx, dy in MOVS: nx, ny = dx + pos[0], dy + pos[1] if not check(nx) or not check(ny): continue if (nx, ny) in set1: continue dic1[nx, ny] = lap % 2 set1.add((nx, ny)) cango1(matrix, (nx, ny), lap + 1) def cango2(matrix, pos, lap): for dx, dy in MOVS: nx, ny = dx + pos[0], dy + pos[1] if not check(nx) or not check(ny): continue if (nx, ny) in set2: continue dic2[nx, ny] = lap % 2 set2.add((nx, ny)) cango2(matrix, (nx, ny), lap + 1) q = int(input()) for ww in range(q): matrix = [input().strip() for i in range(8)] pos = [] bad = set() for i in range(8): for j in range(8): if matrix[i][j] == "K": pos.append((i, j)) if matrix[i][j] == "#": bad.add((i, j)) set1, set2, dic1, dic2 = set(), set(), dict(), dict() cango1(matrix, pos[0], 0) cango2(matrix, pos[1], 0) if ww != q - 1: input() sec = (set1 & set2) - bad for x, y in sec: if dic1[x, y] == dic2[x, y]: print("YES") break else: print("NO")
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = [int(s) for s in input().split()] n, m = max(n, m), min(n, m) if n + m - 2 < k: print(-1) elif n - 1 < k: print(m // (k - n + 2)) elif m - 1 < k: print(n // (k + 1) * m) else: print(max(n // (k + 1) * m, m // (k + 1) * n))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) n, m = min(n, m), max(n, m) def p(i, j): return n // (i + 1) * (m // (j + 1)) if k < n: print(max(p(k, 0), p(0, k))) elif k < m: print(p(0, k)) elif k <= n + m - 2: print(p(k - (m - 1), m - 1)) else: print(-1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) if k > n + m - 2: print(-1) exit() res = 0 if k < n: res = max(res, n // (k + 1) * m) else: res = max(res, m // (k - (n - 1) + 1)) if k < m: res = max(res, m // (k + 1) * n) else: res = max(res, n // (k - (m - 1) + 1)) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) if k > n + m - 2: print(-1) else: a, b = m * (n // (k + 1)), n * (m // (k + 1)) if a == 0: a = m // (k - n + 2) if b == 0: b = n // (k - m + 2) print(max(a, b))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def split1(m, n, k): if m % (k + 1) == 0: return n * (m // (k + 1)) if k < m: return m // (k + 1) * n else: k2 = k - m + 1 return n // (k2 + 1) def split(m, n, k): r = max(split1(m, n, k), split1(n, m, k)) return r if r else -1 args = input().split() print(split(*map(int, args)))
FUNC_DEF IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
a = input().split(" ") n = int(a[0]) m = int(a[1]) k = int(a[2]) if k > m + n - 2: print(-1) else: ans = 1 if k < n: ans = max(ans, n // (k + 1) * m) if k < m: ans = max(ans, m // (k + 1) * n) if k >= n: ans = max(ans, m // (k - (n - 1) + 1)) if k >= m: ans = max(ans, n // (k - (m - 1) + 1)) print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = list(map(int, input().split())) if n + m - 2 < k: print("-1\n") else: x = min(n - 1, k) y = max(0, k - x) ans = n // (x + 1) * (m // (y + 1)) y = min(m - 1, k) x = max(0, k - y) ans = max(ans, n // (x + 1) * (m // (y + 1))) print(ans, "\n")
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def split1(m, n, k): if k < m: return m // (k + 1) * n else: return n // (k - m + 2) def split(m, n, k): r = max(split1(m, n, k), split1(n, m, k)) return r if r else -1 args = input().split() print(split(*list(map(int, args))))
FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) if k <= n + m - 2: x = min(k + 1, n) y = k + 2 - x a = n // x * (m // y) y = min(k + 1, m) x = k + 2 - y b = n // x * (m // y) print(max(a, b)) else: print(-1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) if k > n + m - 2: print(-1) else: if n < m: n, m = m, n if m % (k + 1) == 0: print(m * n // (k + 1)) elif k <= n - 1: if k > m - 1: print(n // (k + 1) * m) else: print(max(n // (k + 1) * m, m // (k + 1) * n)) else: print(m // (k - (n - 1) + 1))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = list(map(int, input().split())) ans, ans1 = 0, 0 if n + m - 2 < k: print(-1) return else: k1 = k if k < n: ans = n // (k + 1) * m else: k -= n - 1 ans = m // (k + 1) if k1 < m: ans1 = m // (k1 + 1) * n else: k1 -= m - 1 ans1 = n // (k1 + 1) print(max(ans1, ans))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def cut(n, m, k): if k > m + n - 2: return -1 if k < max(m, n): return max(n * (m // (k + 1)), m * (n // (k + 1))) return max(n // (k - m + 2), m // (k - n + 2)) n, m, k = map(int, input().split()) print(cut(n, m, k))
FUNC_DEF IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def read(mode=2): inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return [int(x) for x in inputs.split()] def write(s="\n"): if isinstance(s, list): s = " ".join(map(str, s)) s = str(s) print(s, end="") n, m, k = read() if n + m - 2 < k: print(-1) else: mx = 0 if n > k: mx = max(mx, n // (k + 1) * m) else: mx = max(mx, 1 * (m // (k - n + 2))) if m > k: mx = max(mx, m // (k + 1) * n) else: mx = max(mx, 1 * (n // (k - m + 2))) print(mx)
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def main(): n, m, k = [int(i) for i in input().split()] if k > n + m - 2: print(-1) return if k > n - 1: result1 = m // (k + 2 - n) else: result1 = n // (k + 1) * m if k > m - 1: result2 = n // (k + 2 - m) else: result2 = m // (k + 1) * n print(max(result1, result2)) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) if m > n: n, m = m, n ans = -1 if k < n: ans = m * (n // (k + 1)) if k < m: ans = max(ans, n * (m // (k + 1))) elif k <= n - 1 + m - 1: ans = m // (k + 1 - n + 1) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
l = input().split() n = int(l[0]) m = int(l[1]) k = int(l[2]) if k <= n + m - 2: if k < n: outn = int(n / (k + 1)) * m else: outn = int(m / (k - n + 2)) if k < m: outm = int(m / (k + 1)) * n else: outm = int(n / (k - m + 2)) print("", max(outn, outm), sep="") else: print("-1")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def Calc(n, m, k): if n + m - 2 < k: return -1 if k <= n - 1: return n // (k + 1) * m return m // (k - n + 2) n, m, k = [int(x) for x in input().split()] print(max(Calc(n, m, k), Calc(m, n, k)))
FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = map(int, input().split()) if n + m - 2 < k: print(-1) return def divisors(n): div = set() for i in range(1, int(n ** (1 / 2)) + 1): if n % i == 0: div.add(i) div.add(n // i) return [*div] def solve(n, m, k): div = divisors(n) ans = 0 for i in div: if i - 1 > k: continue ans = max(ans, n // i * (m // (k - i + 2))) return ans print(max(solve(n, m, k), solve(m, n, k)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN LIST VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
def main(): a, b, c = map(int, input().split()) res, c = [-1], c + 1 if c < a + b: for n, m, k in ((a, b, c), (b, a, c)): if n < k: k -= n - 1 n, m = m, 1 res.append(n // k * m) print(max(res)) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR FOR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
from itertools import * def read_ints(): return map(int, input().strip().split()) n, m, k = read_ints() def val(x, k, n, m): Y = x + 1 Z = k - x + 1 if Y > 0 and Z > 0: return n // (x + 1) * (m // (k - x + 1)) def sym(n, m, k): x = min(n - 1, k) return val(x, k, n, m) def test(n, m, k): if n + m + 2 < k: return -1 answers = [sym(n, m, k), sym(m, n, k)] return max(answers) or -1 print(test(n, m, k))
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
n, m, k = [int(x) for x in input().split()] if k + 2 > n + m: print(-1) else: if k >= n: alpha = m // (k - n + 2) else: alpha = m * (n // (k + 1)) if k >= m: beta = n // (k - m + 2) else: beta = n * (m // (k + 1)) print(max(alpha, beta))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
inputx = input().split(" ") n = int(inputx[0]) m = int(inputx[1]) k = int(inputx[2]) if n + m - 2 < k: print(-1) else: if n > m: n, m = m, n if k < n: print(max(n * int(m / (k + 1)), m * int(n / (k + 1)))) elif n <= k and k < m: print(n * int(m / (k + 1))) else: print(int(n / (k - m + 2)))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); each cut should go inside the whole chocolate bar, and all cuts must be distinct. The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times. [Image] Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it. -----Input----- A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9). -----Output----- Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1. -----Examples----- Input 3 4 1 Output 6 Input 6 4 2 Output 8 Input 2 3 4 Output -1 -----Note----- In the first sample, Jzzhu can cut the chocolate following the picture below: [Image] In the second sample the optimal division looks like this: [Image] In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
a, b, k = list(map(int, input().split())) if a + b - 2 < k: print(-1) return k += 2 if a > b: a, b = b, a i = 1 maxi = -1 while i * i <= a: y = min(i, k - 1) val1 = a // y * (b // (k - y)) if maxi < val1: maxi = val1 j = min(a // i, k - 1) val2 = a // j * (b // (k - j)) if maxi < val2: maxi = val2 i += 1 print(maxi)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hamming distance between strings a and b of equal length (denoted by h(a, b)) is equal to the number of distinct integers i (1 ≤ i ≤ |a|), such that ai ≠ bi, where ai is the i-th symbol of string a, bi is the i-th symbol of string b. For example, the Hamming distance between strings "aba" and "bba" equals 1, they have different first symbols. For strings "bbba" and "aaab" the Hamming distance equals 4. John Doe had a paper on which four strings of equal length s1, s2, s3 and s4 were written. Each string si consisted only of lowercase letters "a" and "b". John found the Hamming distances between all pairs of strings he had. Then he lost the paper with the strings but he didn't lose the Hamming distances between all pairs. Help John restore the strings; find some four strings s'1, s'2, s'3, s'4 of equal length that consist only of lowercase letters "a" and "b", such that the pairwise Hamming distances between them are the same as between John's strings. More formally, set s'i must satisfy the condition <image>. To make the strings easier to put down on a piece of paper, you should choose among all suitable sets of strings the one that has strings of minimum length. Input The first line contains space-separated integers h(s1, s2), h(s1, s3), h(s1, s4). The second line contains space-separated integers h(s2, s3) and h(s2, s4). The third line contains the single integer h(s3, s4). All given integers h(si, sj) are non-negative and do not exceed 105. It is guaranteed that at least one number h(si, sj) is positive. Output Print -1 if there's no suitable set of strings. Otherwise print on the first line number len — the length of each string. On the i-th of the next four lines print string s'i. If there are multiple sets with the minimum length of the strings, print any of them. Examples Input 4 4 4 4 4 4 Output 6 aaaabb aabbaa bbaaaa bbbbbb
def get_input(): a, b, d = map(int, input().split()) c, e = map(int, input().split()) f = int(input()) return [a, b, c, d, e, f] def check_condition(a, b, c, d, e, f): condition1 = (a + b + c) % 2 == 0 condition2 = (d + e + a) % 2 == 0 condition3 = (e + f + c) % 2 == 0 condition4 = (d + f + b) % 2 == 0 condition = condition1 and condition2 and condition3 and condition4 return condition def find_t(a, b, c, d, e, f): t_min1 = round((d + f - a - c) / 2) t_min2 = round((e + f - a - b) / 2) t_min3 = round((d + e - b - c) / 2) t_min4 = 0 t_min = max(t_min1, t_min2, t_min3, t_min4) t_max1 = round((d + e - a) / 2) t_max2 = round((e + f - c) / 2) t_max3 = round((d + f - b) / 2) t_max = min(t_max1, t_max2, t_max3) if t_min <= t_max: return t_min else: return -1 def find_all(a, b, c, d, e, f, t): x1 = round((a + c - d - f) / 2 + t) x2 = round((d + f - b) / 2 - t) y1 = round((a + b - e - f) / 2 + t) y2 = round((e + f - c) / 2 - t) z1 = round((b + c - d - e) / 2 + t) z2 = round((d + e - a) / 2 - t) return [x1, x2, y1, y2, z1, z2] def generate_string(x1, x2, y1, y2, z1, z2, t): n = x1 + x2 + y1 + y2 + z1 + z2 + t s1 = "".join(["a"] * n) s2 = "".join(["a"] * (z1 + z2 + t)) + "".join(["b"] * (x1 + x2 + y1 + y2)) s3 = ( "".join(["a"] * t) + "".join(["b"] * (y1 + y2 + z1 + z2)) + "".join(["a"] * (x1 + x2)) ) s4 = ( "".join(["b"] * (t + z2)) + "".join(["a"] * (z1 + y2)) + "".join(["b"] * (y1 + x2)) + "".join(["a"] * x1) ) return [s1, s2, s3, s4] def __main__(): fail_output = "-1" a, b, c, d, e, f = map(int, get_input()) if not check_condition(a, b, c, d, e, f): print(fail_output) return False t = find_t(a, b, c, d, e, f) if t < 0: print(fail_output) return False x1, x2, y1, y2, z1, z2 = map(int, find_all(a, b, c, d, e, f, t)) s1, s2, s3, s4 = map(str, generate_string(x1, x2, y1, y2, z1, z2, t)) print(str(x1 + x2 + y1 + y2 + z1 + z2 + t) + "\n") print(s1 + "\n") print(s2 + "\n") print(s3 + "\n") print(s4 + "\n") __main__()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN LIST VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR RETURN LIST VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP FUNC_CALL STRING BIN_OP LIST STRING BIN_OP BIN_OP VAR VAR VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL STRING BIN_OP LIST STRING VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL STRING BIN_OP LIST STRING BIN_OP VAR VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP VAR VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP VAR VAR FUNC_CALL STRING BIN_OP LIST STRING VAR RETURN LIST VAR VAR VAR VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR
Hamming distance between strings a and b of equal length (denoted by h(a, b)) is equal to the number of distinct integers i (1 ≤ i ≤ |a|), such that ai ≠ bi, where ai is the i-th symbol of string a, bi is the i-th symbol of string b. For example, the Hamming distance between strings "aba" and "bba" equals 1, they have different first symbols. For strings "bbba" and "aaab" the Hamming distance equals 4. John Doe had a paper on which four strings of equal length s1, s2, s3 and s4 were written. Each string si consisted only of lowercase letters "a" and "b". John found the Hamming distances between all pairs of strings he had. Then he lost the paper with the strings but he didn't lose the Hamming distances between all pairs. Help John restore the strings; find some four strings s'1, s'2, s'3, s'4 of equal length that consist only of lowercase letters "a" and "b", such that the pairwise Hamming distances between them are the same as between John's strings. More formally, set s'i must satisfy the condition <image>. To make the strings easier to put down on a piece of paper, you should choose among all suitable sets of strings the one that has strings of minimum length. Input The first line contains space-separated integers h(s1, s2), h(s1, s3), h(s1, s4). The second line contains space-separated integers h(s2, s3) and h(s2, s4). The third line contains the single integer h(s3, s4). All given integers h(si, sj) are non-negative and do not exceed 105. It is guaranteed that at least one number h(si, sj) is positive. Output Print -1 if there's no suitable set of strings. Otherwise print on the first line number len — the length of each string. On the i-th of the next four lines print string s'i. If there are multiple sets with the minimum length of the strings, print any of them. Examples Input 4 4 4 4 4 4 Output 6 aaaabb aabbaa bbaaaa bbbbbb
h = [[0 in range(10)] for j in range(10)] for i in range(1, 4): h[i] = [(0) for j in range(i + 1)] + list(map(int, input().split())) if h[1][2] + h[1][3] < h[2][3] or (h[1][2] + h[1][3] - h[2][3]) % 2 == 1: print("-1") exit(0) BB = (h[1][2] + h[1][3] - h[2][3]) // 2 BA = h[1][2] - BB AB = h[1][3] - BB NowB = h[1][4] NowLen = BB + AB + BA Now24 = BA + NowB + BB Now34 = AB + NowB + BB BAB = 0 ABB = 0 BBB = 0 Dif = BA - AB - (h[2][4] - h[3][4]) if abs(Dif) % 2 == 1: print("-1") exit(0) if Dif < 0: ABB += abs(Dif) // 2 Now34 -= ABB * 2 if AB < ABB or NowB < ABB: print("-1") exit(0) NowB -= ABB else: BAB += Dif // 2 Now24 -= BAB * 2 if BA < BAB or NowB < BAB: print("-1") exit(0) NowB -= BAB if Now24 < h[2][4] or (Now24 - h[2][4]) % 2 == 1: print("-1") exit(0) for i in range(BB + 1): if i > NowB: break Now = i * 2 if Now > Now24 - h[2][4]: break if min([(NowB - i) // 2, BA - BAB, AB - ABB]) * 2 >= Now24 - h[2][4] - Now: BBB += i BAB += (Now24 - h[2][4] - Now) // 2 ABB += (Now24 - h[2][4] - Now) // 2 NowB -= i + (Now24 - h[2][4] - Now) print(NowLen + NowB) print("".join(["a" for j in range(NowLen)] + ["a" for j in range(NowB)])) print( "".join( ["a" for j in range(AB)] + ["b" for j in range(BB + BA)] + ["a" for j in range(NowB)] ) ) print( "".join( ["b" for j in range(AB + BB)] + ["a" for j in range(BA)] + ["a" for j in range(NowB)] ) ) print( "".join( ["b" for j in range(ABB)] + ["a" for j in range(AB - ABB)] + ["b" for j in range(BBB)] + ["a" for j in range(BB - BBB)] + ["b" for j in range(BAB)] + ["a" for j in range(BA - BAB)] + ["b" for j in range(NowB)] ) ) exit(0) print("-1")
ASSIGN VAR LIST NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) ans = 0 c = b if b < f: ans = -1 else: c -= f for i in range(k): if ans == -1: break if i % 2 == 0: d = a - f else: d = f if i < k - 1: d *= 2 if b < d: ans = -1 elif c < d: ans += 1 c = b c -= d print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def solve(a, b, f, k): origb = b disa = 2 * f disb = 2 * (a - f) trava = False counter = 0 b -= disa / 2 if b < 0: return -1 while k > 0: if trava: trava = False if k == 1: disa = disa / 2 if disa > b: counter += 1 b = origb - disa if b < 0: return -1 k -= 1 else: b -= disa if b < 0: return -1 k -= 1 else: trava = True if k == 1: disb = disb / 2 if disb > b: counter += 1 b = origb - disb if b < 0: return -1 k -= 1 else: b -= disb if b < 0: return -1 k -= 1 return counter inputs = input("") afind = inputs.find(" ") a = int(inputs[0:afind]) inputs = inputs[afind + 1 :] afind = inputs.find(" ") b = int(inputs[0:afind]) inputs = inputs[afind + 1 :] afind = inputs.find(" ") f = int(inputs[0:afind]) inputs = inputs[afind + 1 :] k = int(inputs[0:]) print(solve(a, b, f, k))
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) c = b cnt = 0 if cnt == 0: for i in range(k): if i & 1 == 0: dis = a - f else: dis = f c -= a - dis if c < 0: cnt = -1 break if i < k - 1 and c < 2 * dis: cnt += 1 c = b if i == k - 1 and c < dis: cnt += 1 c = b c -= dis if c < 0: cnt = -1 break print(cnt)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) ans = 0 cb = b for i in range(k): if i % 2 == 0: if f > cb: print(-1) return else: cb -= f if i != k - 1: if cb < 2 * (a - f): ans += 1 cb = b cb -= a - f else: if cb < a - f: ans += 1 cb = b cb -= a - f if cb < 0: print(-1) return elif a - f > cb: print(-1) return else: cb -= a - f if i != k - 1: if cb < 2 * f: ans += 1 cb = b cb -= f else: if cb < f: ans += 1 cb = b cb -= f if cb < 0: print(-1) return print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) x, y = f, a - f if k == 1: if b < max(x, y): print(-1) quit() elif k == 2: if b < max(x, 2 * y): print(-1) quit() elif b < max(2 * x, 2 * y): print(-1) quit() gas = b refill = 0 test = True while k > 0: if test: if gas >= x + 2 * y: gas -= a elif gas >= x: if k == 1: if gas >= a: break gas = b - y refill += 1 else: print(-1) quit() test = not test else: if gas >= 2 * x + y: gas -= a elif gas >= y: if k == 1: if gas >= a: break gas = b - x refill += 1 else: print(-1) quit() test = not test k -= 1 print(refill)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR IF VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) g = a - f t = b - f s = 0 while t >= 0: if t >= g: k -= 1 t -= g else: t = b - g s += 1 if t < 0: break k -= 1 if k == 0: break if t >= g: t -= g else: t = b - 2 * g s += 1 if t < 0: break if t >= f: k -= 1 t -= f else: t = b - f s += 1 if t < 0: break k -= 1 if k == 0: break if t >= f: t -= f else: t = b - 2 * f s += 1 if t < 0: break print(-1 if k else s)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = [int(z) for z in input().split()] to_fuel = f from_fuel = a - f alrdy_fueled = 0 petrol = b for i in range(k): petrol -= to_fuel if petrol < 0: print(-1) exit(0) if petrol < 2 * from_fuel and i != k - 1: petrol = b alrdy_fueled += 1 elif i == k - 1: if petrol < from_fuel: petrol = b alrdy_fueled += 1 petrol -= from_fuel if petrol < 0: print(-1) exit(0) to_fuel, from_fuel = from_fuel, to_fuel print(alrdy_fueled)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys def min_refills(end_point, capacity, fuel_point, journeys): fuel = capacity journey_count = 0 refills = 0 while True: fuel -= fuel_point if fuel < 0: return -1 fuel_needed = ( 2 * (end_point - fuel_point) if journey_count < journeys - 1 else end_point - fuel_point ) if fuel_needed > fuel: refills += 1 fuel = capacity if fuel_needed > capacity: return -1 fuel -= end_point - fuel_point journey_count += 1 if journey_count == journeys: break fuel -= end_point - fuel_point fuel_needed = 2 * fuel_point if journey_count < journeys - 1 else fuel_point if fuel_needed > fuel: refills += 1 fuel = capacity if fuel_needed > capacity: return -1 fuel -= fuel_point journey_count += 1 if journey_count == journeys: break return refills line = sys.stdin.readline() print(min_refills(*[int(x) for x in line.split()]))
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def main(): a, b, f, k = map(int, input().split()) if b < f or b < a - f: print(-1) elif k >= 2 and b < 2 * (a - f): print(-1) elif k > 2 and b < 2 * f: print(-1) else: refuel, fuel = 0, b for i in range(k - 1): if i % 2: if fuel < f + a: refuel += 1 fuel = b - f else: fuel = fuel - a elif fuel < 2 * a - f: refuel += 1 fuel = b - (a - f) else: fuel = fuel - a if fuel < a: refuel += 1 print(refuel) main()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = list(map(int, input().split())) i = 0 bi = b ans = 0 while i < k: if f > bi: print(-1) return bi -= f if k - i == 1: if a - f > bi: bi = b ans += 1 if a - f > b: print(-1) return break i += 1 if 2 * (a - f) > bi: bi = b ans += 1 if 2 * (a - f) > b: print(-1) return bi -= 2 * (a - f) if k - i == 1: if f > bi: bi = b ans += 1 break if 2 * f > bi: bi = b ans += 1 if 2 * f > b: print(-1) return bi -= f i += 1 print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR BIN_OP NUMBER BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def solve(a, b, f, k): cur_b = b cur_k = 0 refueling_count = 0 can_0f = cur_b - f >= 0 if not can_0f: return refueling_count, cur_k else: cur_b -= f while cur_k < k: faf_path = 2 * (a - f) can_faf = cur_b - faf_path >= 0 can_faf_with_refueling = b - faf_path >= 0 can_fa = cur_b - (a - f) >= 0 can_fa_with_refueling = b - (a - f) >= 0 if can_faf and k - cur_k > 1: cur_b = cur_b - faf_path cur_k += 1 elif can_faf_with_refueling and k - cur_k > 1: refueling_count += 1 cur_b = b - faf_path cur_k += 1 elif can_fa: cur_k += 1 return refueling_count, cur_k elif can_fa_with_refueling: cur_k += 1 refueling_count += 1 return refueling_count, cur_k else: return refueling_count, cur_k if cur_k == k: return refueling_count, cur_k f0f_path = 2 * f can_f0f = cur_b - f0f_path >= 0 can_f0f_with_refueling = b - f0f_path >= 0 can_f0 = cur_b - f >= 0 can_f0_with_refueling = b - f >= 0 if can_f0f and k - cur_k > 1: cur_b = cur_b - f0f_path cur_k += 1 elif can_f0f_with_refueling and k - cur_k > 1: refueling_count += 1 cur_b = b - f0f_path cur_k += 1 elif can_f0: cur_k += 1 return refueling_count, cur_k elif can_f0_with_refueling: cur_k += 1 refueling_count += 1 return refueling_count, cur_k else: return refueling_count, cur_k return refueling_count, cur_k def main(): a, b, f, k = map(int, input().split()) refueling_count, cur_k = solve(a, b, f, k) if cur_k == k: print(refueling_count) else: print(-1) main()
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR RETURN VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER RETURN VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN VAR VAR RETURN VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER RETURN VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) ans = 0 t = b l = a - f x = 0 if b < max(f, l): ans = -1 else: while k > 0: if x == 0: t -= f if t < 0: ans = -1 break t -= l if k == 1: l = 0 if b - l < 0: ans = -1 break if t - l < 0: t = b - l ans += 1 k -= 1 x = a else: t -= l if t < 0: ans = -1 break t -= f if k == 1: f = 0 if b - f < 0: ans = -1 break if t - f < 0: t = b - f ans += 1 k -= 1 x = 0 print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys a, b, f, k = map(int, input().split()) def game_over(): print(-1) sys.exit() fuel = b add_fuel_count = 0 distance_to_stop = f fuel_on_next_stop = fuel - distance_to_stop if fuel_on_next_stop < 0: game_over() for i in range(1, k + 1): fuel = fuel_on_next_stop if i == k: if i % 2: distance_to_stop = a - f else: distance_to_stop = f elif i % 2: distance_to_stop = 2 * (a - f) else: distance_to_stop = 2 * f if fuel < distance_to_stop: fuel, add_fuel_count = b, add_fuel_count + 1 fuel_on_next_stop = fuel - distance_to_stop if fuel_on_next_stop < 0: game_over() print(add_fuel_count)
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def predict(x, p): if x == 1: if p - a - f >= 0: return "Go" return "Fuel" elif p - (a + a - f) >= 0: return "Go" else: return "Fuel" a, b, f, k = map(int, input().split()) t = 0 r = 0 www = b for i in range(k): if i == k - 1: if b >= a: continue if i % 2 == 0: d = predict(i % 2, b) if d == "Go": b -= a elif b >= f and a - b <= a - f and b >= 0: b = www b -= a - f if b < 0: r = 1 break t += 1 else: r = 1 break else: d = predict(i % 2, b) if d == "Go": b -= a elif b >= a - f: b = www b -= f if b < 0: r = 1 break t += 1 else: r = 1 break if r == 1: print("-1") else: print(t)
FUNC_DEF IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN STRING RETURN STRING IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING VAR VAR IF VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) x = 0 rf = 0 fuel = b di = 0 j = 0 if fuel < f: print(-1) exit() x = f fuel -= f while j != k: if di == 0: if j == k - 1: if fuel >= a - f: print(rf) exit() if fuel >= 2 * (a - f): fuel = fuel - 2 * (a - f) di = 1 else: rf = rf + 1 if b >= a - f and j == k - 1: print(rf) exit() fuel = b - 2 * (a - f) if fuel < 0: print(-1) exit() di = 1 j += 1 elif di == 1: if j == k - 1: if fuel >= f: print(rf) exit() if fuel >= 2 * f: x = f di = 0 fuel -= 2 * f else: rf = rf + 1 if b >= f and j == k - 1: print(rf) exit() fuel = b - 2 * f if fuel < 0: print(-1) exit() x = f di = 0 j += 1 print(rf)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def main(): a, b, f, k = list(map(int, input().split())) fuels = 0 trips = 0 pos = 0 move = 1 gas = b while trips < k: if gas < 0: print(-1) return if move == 1: if pos == 0: pos = f gas -= f elif pos == f: needed_gas = a - f if trips == k - 1 else 2 * (a - f) if gas < needed_gas: gas = b fuels += 1 gas -= a - f pos = a elif pos == a: trips += 1 if trips == k: break move = -1 elif move == -1: if pos == 0: trips += 1 if trips == k: break move = 1 elif pos == f: needed_gas = f if trips == k - 1 else 2 * f if gas < needed_gas: gas = b fuels += 1 pos = 0 gas -= f elif pos == a: pos = f gas -= a - f print(fuels) main()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) im = False fuel = b cnt = 0 for i in range(k): if i % 2 == 0: if fuel - f < 0: im = True break if i < k - 1: if fuel - (2 * a - f) < 0: cnt += 1 fuel = b - (a - f) else: fuel -= a elif fuel - a < 0: cnt += 1 fuel = b - (a - f) else: fuel -= a else: if fuel - (a - f) < 0: im = True break if i < k - 1: if fuel - (a + f) < 0: cnt += 1 fuel = b - f else: fuel -= a elif fuel - a < 0: cnt += 1 fuel = b - f else: fuel -= a if fuel < 0: im = True break print(-1 if im else cnt)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
from sys import stdin, stdout a, b, f, k = map(int, stdin.readline().split()) ans, position = 0, 0 current = b label = 1 for i in range(k): if not position: distance = a + a - f curd = a - f last = a oil = f else: distance = a + f curd = f last = 0 oil = a - f if distance <= current or a <= current and i == k - 1: current -= a elif oil <= current: ans += 1 current = b - curd else: current = -1 position = last if current < 0: label = 0 if not label: stdout.write("-1") else: stdout.write(str(ans))
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) def distanceToFuel(pos): return a - f if pos else f if f > b: print(-1) else: total = k * a pos = 0 remaining = b refuel = 0 while total > 0: remaining -= distanceToFuel(pos) total -= distanceToFuel(pos) if k == 1: if distanceToFuel(pos ^ 1) > b: refuel = -1 break elif remaining < distanceToFuel(pos ^ 1): refuel = 1 break else: refuel = 0 break if total == distanceToFuel(pos ^ 1): if remaining >= distanceToFuel(pos ^ 1): break else: refuel += 1 break elif 2 * distanceToFuel(pos ^ 1) > remaining: if 2 * distanceToFuel(pos ^ 1) > b: refuel = -1 break remaining = b refuel += 1 pos ^= 1 total -= distanceToFuel(pos) remaining -= distanceToFuel(pos) print(refuel)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys a, b, f, k = list(map(int, input().split())) d1 = f d2 = a - f if k == 1: if d1 > b or d2 > b: print("-1") sys.exit() elif k == 2: if d1 > b or 2 * d2 > b: print("-1") sys.exit() elif 2 * d1 > b or 2 * d2 > b: print("-1") sys.exit() rem = b fill = 0 for i in range(k): round = i + 1 if round % 2 != 0: rem -= d1 if round == k and rem >= d2: rem -= d2 elif round != k and rem >= 2 * d2: rem -= d2 else: fill += 1 rem = b rem -= d2 else: rem -= d2 if round == k and rem >= d1: rem -= d1 elif round != k and rem >= 2 * d1: rem -= d1 else: fill += 1 rem = b rem -= d1 print(fill)
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
from sys import stdin, stdout a, b, f, k = list(map(int, stdin.readline().rstrip().split())) direction = 1 tank = b refuels = 0 position = 0 if b < f or b < a - f: possible = False else: possible = True while k > 0 and possible == True: if k == 1 and tank >= a: k = 0 elif k == 1: k = 0 refuels += 1 elif position == 0: position = f tank -= f direction = 1 elif position == a: position = f tank -= a - f direction = -1 elif direction == 1: if tank < 2 * (a - f): tank = b refuels += 1 if b < 2 * (a - f): possible = False else: position = a direction = -1 tank -= a - f k -= 1 elif direction == -1: if tank < 2 * f: refuels += 1 tank = b if b < 2 * f: possible = False else: position = 0 direction = 1 tank -= f k -= 1 if not possible: print(-1) else: print(refuels)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def bus(): [a, b, f, k] = map(int, input().split()) if b < f: return -1 trips, fuel, pos, refill = 0, b - f, f, 0 while trips < k: rounds = 2 * (fuel // (2 * a)) fuel -= rounds * a if pos == f and fuel % (2 * a) >= 2 * (a - f): rounds += 1 pos = a + f fuel -= 2 * (a - f) elif pos == a + f and fuel % (2 * a) >= 2 * f: rounds += 1 pos = f fuel -= 2 * f trips += rounds if trips == k - 1: if pos == f and fuel >= a - f or pos == a + f and fuel >= f: return refill elif trips >= k: return refill if rounds == 0: if fuel < b: fuel, refill = b, refill + 1 else: return -1 else: fuel, refill = b, refill + 1 return refill print(bus())
FUNC_DEF ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR IF VAR VAR RETURN VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) if (f > b or a - f > b) or k > 1 and 2 * (a - f) > b or k > 2 and 2 * f > b: print(-1) exit() cur = b ans = 0 for i in range(k): if i & 1 == 0: if cur < f: cur = b - f ans += 1 if cur >= a: cur -= a else: ans += 1 cur = b - a + f else: if cur < a - f: cur = b - a + f ans += 1 if cur >= a: cur -= a else: ans += 1 cur = b - f print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
line = input() thing = list(map(int, line.split())) a = thing[0] b = thing[1] f = thing[2] k = thing[3] fuel = b - f fa = True refuels = 0 trips = 0 while True: if fuel < 0: refuels = -1 break if fa: if trips + 1 == k: distance = a - f if fuel < distance: refuels += 1 fuel = b if b < distance: refuels = -1 break break distance = 2 * (a - f) if fuel < distance: refuels += 1 fuel = b if b < distance: refuels = -1 break fuel = fuel - distance trips += 1 fa = False if not fa: if trips + 1 == k: distance = f if fuel < distance: refuels += 1 fuel = b if b < distance: refuels = -1 break break distance = 2 * f if fuel < distance: refuels += 1 fuel = b if b < distance: refuels = -1 break fuel = fuel - distance trips += 1 fa = True print(refuels)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def read_input(): input_str = str(input()) return map(int, input_str.split(" ")) def check(a: int, b: int, f: int, k: int) -> int: if k == 1 and (a - f > b or f > b): return -1 elif k == 2 and ((a - f) * 2 > b or f > b): return -1 elif k > 2 and ((a - f) * 2 > b or f * 2 > b): return -1 counter = 0 actual_b = b - f for i in range(k - 1): if i % 2 == 0: if actual_b < (a - f) * 2: counter += 1 actual_b = b actual_b -= (a - f) * 2 else: if actual_b < f * 2: counter += 1 actual_b = b actual_b -= f * 2 if k % 2 == 1: if actual_b < a - f: counter += 1 actual_b = b elif actual_b < f: counter += 1 actual_b = b return counter a, b, f, k = read_input() result = check(a, b, f, k) print(result)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR RETURN NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) counter = 0 b2 = b - f if b2 >= 0: dist2 = (a - f) * 2 for i in range(k): if i == k - 1: dist2 /= 2 if b2 < dist2: b2 = b counter += 1 b2 -= dist2 if b2 < 0: counter = -1 break dist2 = 2 * a - dist2 print(counter) else: print(-1)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = [int(i) for i in input().split()] if k >= 3: if f > b or 2 * f > b or 2 * (a - f) > b: print(-1) else: fuel = 0 fwd = 1 rem = b - f while k != 1: if fwd == 1: if rem >= 2 * (a - f): rem = rem - 2 * (a - f) else: rem = b - 2 * (a - f) fuel += 1 k -= 1 fwd = 0 else: if rem >= 2 * f: rem = rem - 2 * f else: rem = b - 2 * f fuel += 1 k -= 1 fwd = 1 if fwd == 1: if rem >= a - f: print(fuel) else: print(fuel + 1) elif rem >= f: print(fuel) else: print(fuel + 1) elif k == 1: if f > b or a - f > b: print(-1) elif b >= a: print(0) else: print(1) elif f > b or 2 * (a - f) > b: print(-1) else: fuel = 0 rem = b - f if rem < 2 * (a - f): rem = b - 2 * (a - f) fuel += 1 else: rem = rem - 2 * (a - f) if rem >= f: print(fuel) else: print(fuel + 1)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
DEBUG = False def cover_distance(): a, b, f, k = map(int, input().split()) fuel = b add_fuel_count = 0 fuel_on_next_stop = fuel - f if fuel_on_next_stop < 0: return -1 distance_to_destination = 0 distance_to_gas_station = 0 for i in range(1, k + 1): if DEBUG: print("i= {} : ".format(i)) print("\t fuel_on_station = {} ".format(fuel_on_next_stop)) if i == k: if i % 2: distance_to_destination = a - f else: distance_to_destination = f fuel = fuel_on_next_stop if fuel < distance_to_destination: fuel = b add_fuel_count += 1 fuel_on_next_stop = fuel - distance_to_destination else: if i % 2: distance_to_gas_station = 2 * (a - f) else: distance_to_gas_station = 2 * f fuel = fuel_on_next_stop if fuel < distance_to_gas_station: fuel = b add_fuel_count += 1 fuel_on_next_stop = fuel - distance_to_gas_station if DEBUG: if distance_to_destination: distance = distance_to_destination else: distance = distance_to_gas_station print("\t distance = {} ".format(distance)) print("\t fuel_on_next_stop = {} ".format(fuel_on_next_stop)) if fuel == b: print("\t YES") if fuel_on_next_stop < 0: return -1 return add_fuel_count print(cover_distance())
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER RETURN NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) ff = 1 if k == 1: if b >= a: print(0) elif b >= f and b >= a - f: print(1) else: print(-1) else: p = b - f ans = 0 for i in range(k - 1): if i % 2 == 0: if b < 2 * (a - f): ff = 0 break if p < 2 * (a - f): p = b - 2 * (a - f) ans += 1 else: p -= 2 * (a - f) else: if b < 2 * f: ff = 0 break if p < 2 * f: p = b - 2 * f ans += 1 else: p -= 2 * f if k % 2 == 0: if b < f: ff = 0 if p < f: ans += 1 elif k % 2 == 1: if b < a - f: ff = 0 if p < a - f: ans += 1 if ff == 0: print(-1) else: print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) s, t = 0, b - f g = f = a - f for i in range(k): if t < 0: break if k - 1 - i: g += f if t < g: s, t = s + 1, b t -= g g = f = a - f print(-1 if t < 0 else s)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) p = 0 r = 0 m = b if k == 1: if m < f or m < a - f: print(-1) quit() d1, d2 = 2 * a - f, a + f for _ in range(k - 1): if p == 0: if f > m: r = -1 break if m < d1: r += 1 m = b - a + f else: m -= a p = a else: if a - f > m: r = -1 if m < d2: r += 1 m = b - f else: m -= a p = 0 if p == 0: if m < f: r = -1 elif m < a: r += 1 elif m < a - f: r = -1 elif m < a: r += 1 print(r)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, c, d = map(int, input().split()) x = b - c f = 1 if b < c or b < a - c or d >= 2 and b < (a - c) * 2 or d > 2 and b < c * 2: print(-1) exit() k = 0 for i in range(d): if i + 1 == d: if f == 1: if x >= a - c: print(k) else: print(k + 1) elif x >= c: print(k) else: print(k + 1) exit() if f == 1: if x >= (a - c) * 2: x = x - (a - c) * 2 else: x = b - (a - c) * 2 k = k + 1 f = 2 else: if x >= c * 2: x = x - c * 2 else: x = b - c * 2 k = k + 1 f = 1
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) if max(2 * f, 2 * (a - f)) > b and k > 2: print("-1") elif k == 1 and max(f, a - f) > b: print("-1") elif k == 2 and (b < 2 * (a - f) or b < f): print("-1") else: m = b dir = 1 l = 0 pos = 1 x = 0 while l < k: if pos == 1 and m >= f and dir == 1: m -= f dir = 1 pos = 2 elif pos == 2 and dir == 1: if k - l > 1 and m >= 2 * (a - f): dir = 2 pos = 2 l += 1 m -= 2 * (a - f) elif k - l == 1 and m >= a - f: l += 1 else: m = b x += 1 elif pos == 2 and dir == 2: if k - l > 1 and m >= 2 * f: dir = 1 pos = 2 l += 1 m -= 2 * f elif k - l == 1 and m >= f: l += 1 else: m = b x += 1 print(x)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = tuple(map(int, input().split())) d1 = f - 0 d2 = a - f def sim(): x = b c = 0 for i in range(1, k + 1, 2): if x < d1: return -1 x -= d1 if x < d2 or i < k and x < 2 * d2: x = b c += 1 if x < d2: return -1 x -= d2 if i == k: break if x < d2: return -1 x -= d2 if x < d1 or i + 1 < k and x < 2 * d1: x = b c += 1 if x < d1: return -1 x -= d1 return c print(sim())
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR IF VAR VAR IF VAR VAR RETURN NUMBER VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys l, tank, v, rep = (int(x) for x in input().split()) checkpoints = [(l * i + (v if i % 2 == 0 else l - v)) for i in range(rep)] checkpoints.append(rep * l) x = 0 gas = tank cnt = 0 for y in checkpoints: if y - x > gas: if y - x > tank: print(-1) sys.exit() cnt += 1 gas = tank gas -= y - x x = y print(cnt)
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) fuel = b res = 0 for i in range(k): fuel -= f if fuel < 0: print(-1) exit(0) if i == k - 1: if a - f > fuel: fuel = b res += 1 fuel -= a - f break if (a - f) * 2 > fuel: fuel = b res += 1 fuel -= a - f f = a - f if fuel < 0: print(-1) exit(0) print(res)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys a, b, f, k = map(int, input().split()) l1 = 2 * (a - f) l2 = 2 * f t = b cnt = 0 r = True if t >= f: t -= f for i in range(k - 1): if r: if t >= l1: t -= l1 r = False elif b >= l1: cnt += 1 t = b - l1 r = False else: print(-1) sys.exit() elif t >= l2: t -= l2 r = True elif b >= l2: cnt += 1 t = b - l2 r = True else: print(-1) sys.exit() if k % 2 == 1: if t >= a - f: print(cnt) elif b >= a - f: print(cnt + 1) else: print(-1) elif t >= f: print(cnt) elif b >= f: print(cnt + 1) else: print(-1) else: print(-1)
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def main(): a, b, f, k = input().split(" ") endpoint = int(a) capacity = int(b) station = int(f) journeys = int(k) print(betterBus(endpoint, capacity, station, journeys)) def bus(endpoint, capacity, station, journeys): refuels = 0 current = capacity to = True for j in range(journeys): r = range(endpoint) if not to: r = range(endpoint, 0, -1) to = True else: to = False for e in r: if e == station: if j == journeys - 1: if current - e < 0: current = capacity refuels += 1 elif current - (endpoint - station) * 2 < 0: current = capacity refuels += 1 elif current == 0: return -1 current -= 1 return refuels def betterBus(endpoint, capacity, station, journeys): refuels = 0 current = capacity to = True for j in range(journeys): if to: current -= station if current < 0: return -1 if j == journeys - 1: if current - (endpoint - station) < 0: current = capacity if current - (endpoint - station) < 0: return -1 refuels += 1 elif current - (endpoint - station) * 2 < 0: current = capacity refuels += 1 current -= endpoint - station to = False else: current -= endpoint - station if current < 0: return -1 if j == journeys - 1: if current - station < 0: current = capacity if current - station < 0: return -1 refuels += 1 elif current - station * 2 < 0: current = capacity refuels += 1 current -= station to = True return refuels main()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def calculate_minimal_refueling(obj_pos, fuel_capacity, gas_station_pos, trip_required): direction = True current_gas = fuel_capacity refuel_count = 0 for trip in range(trip_required): if direction: current_gas -= gas_station_pos if current_gas < 0: return -1 elif ( trip + 1 != trip_required and current_gas < 2 * (obj_pos - gas_station_pos) or current_gas < obj_pos - gas_station_pos ): current_gas = fuel_capacity refuel_count += 1 current_gas -= obj_pos - gas_station_pos if current_gas < 0: return -1 direction = False else: current_gas -= obj_pos - gas_station_pos if current_gas < 0: return -1 elif ( trip + 1 != trip_required and current_gas < 2 * gas_station_pos or current_gas < gas_station_pos ): current_gas = fuel_capacity refuel_count += 1 current_gas -= gas_station_pos if current_gas < 0: return -1 direction = True return refuel_count def main(): a, b, f, k = map(int, input().split()) print(calculate_minimal_refueling(a, b, f, k)) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = [int(x) for x in input().split()] oil = b num = 0 oil -= f if b < f or b < a - f or b < 2 * (a - f) and k >= 2 or b < 2 * f and k >= 3: print(-1) else: for i in range(1, k): if i % 2 == 1: if oil >= 2 * (a - f): oil -= 2 * (a - f) else: oil = b num += 1 oil -= 2 * (a - f) elif oil >= 2 * f: oil -= 2 * f else: oil = b num += 1 oil -= 2 * f if k % 2 == 1: if oil < a - f: num += 1 elif oil < f: num += 1 print(num)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
info = [int(num) for num in input().split()] a = info[0] b = info[1] f = info[2] k = info[3] gas_spots = [(a * i + (f if i % 2 == 0 else a - f)) for i in range(k)] gas_spots.append(k * a) curr_x = 0 curr_gas = b result = 0 for spot in gas_spots: to_travel = spot - curr_x if to_travel > b: print(-1) break elif to_travel > curr_gas: result += 1 curr_gas = b curr_gas -= to_travel curr_x = spot else: print(result)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = list(map(int, input().split())) refill = b busPos = 0 counter = 0 shouldPrint = True while True: busPos += f b -= f if b < 0: print(-1) shouldPrint = False break if (2 if k > 1 else 1) * (a - f) > b: b = refill counter += 1 busPos += a - f b -= a - f if b < 0: print(-1) shouldPrint = False break k -= 1 if k == 0: break busPos -= a - f b -= a - f if b < 0: print(-1) shouldPrint = False break if (2 if k > 1 else 1) * f > b: b = refill counter += 1 busPos -= f b -= f if b < 0: print(-1) shouldPrint = False break k -= 1 if k == 0: break if shouldPrint: print(counter)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) fuel = b - f c, d = 0, [a - f << 1, f << 1] flag = 1 for i in range(k): if fuel < 0: flag = 0 break dis = d[i & 1] * (1 if i != k - 1 else 0.5) if fuel < dis: fuel = b c += 1 fuel -= dis if fuel < 0: flag = 0 print(c if flag else "-1")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
[a, b, f, k] = list(map(int, input().split())) def fail(): print("-1") exit(0) def success(x): print(x) exit(0) res = 0 r = b - f while k > 0: if r < 0: fail() if k == 1: if r < a - f: res += 1 r = b if r < a - f: fail() success(res) else: if r < (a - f) * 2: res += 1 r = b r -= (a - f) * 2 if r < 0: fail() k -= 1 if k == 1: if r < f: res += 1 r = b if r < f: fail() success(res) else: if r < f * 2: res += 1 r = b r -= f * 2 if r < 0: fail() k -= 1
ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
cin = input().split() a = int(cin[0]) b = int(cin[1]) f = int(cin[2]) k = int(cin[3]) fuel = [0] for h in range(k // 2): fuel += [2 * a * h + f, 2 * a * (h + 1) - f] if k % 2 == 1 and k != 1: fuel += [2 * a * (k // 2) + f] elif k == 1: fuel += [f] fuel += [a * k] try: d1 = fuel[2] - fuel[1] d2 = fuel[3] - fuel[2] except: d1 = fuel[1] - fuel[0] d2 = fuel[2] - fuel[1] if d1 > b or d2 > b: print(-1) else: fuelPointer = 0 gas = b refuel = 0 while fuelPointer < len(fuel) - 1: if gas < fuel[fuelPointer + 1] - fuel[fuelPointer]: refuel += 1 gas = b gas -= fuel[fuelPointer + 1] - fuel[fuelPointer] fuelPointer += 1 print(refuel)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR LIST BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR LIST VAR VAR LIST BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys a, v, f, k = map(int, input().split()) st_v = v s1 = f s2 = a - f res = 0 for i in range(2 * k): if i % 2 == 0: if i % 4 == 0: v -= s1 if v < 0: print(-1) sys.exit() if i != 2 * k - 2: if v < 2 * s2: v = st_v res += 1 elif v < s2: v = st_v res += 1 else: v -= s2 if v < 0: print(-1) sys.exit() if i != 2 * k - 2: if v < 2 * s1: v = st_v res += 1 elif v < s1: v = st_v res += 1 else: if (i - 1) % 4 == 0: v -= s2 elif (i - 1) % 4 == 2: v -= s1 if v < 0: print(-1) sys.exit() print(res)
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) p = b i = 0 direct = "p" ans = 0 flag = 0 while k > 0: if i == 0 and p < f or i == a and p < a - f: flag = 1 break elif i == 0: p -= f i = f elif i == a: p -= a - f i = f else: if k == 1: if direct == "p": if p < a - f and b >= a - f: p = b ans += 1 elif b < a - f: flag = 1 break elif direct == "n": if p < f and b >= f: p = b ans += 1 elif b < f: flag = 1 break elif direct == "p": if p < 2 * (a - f) and b >= 2 * (a - f): p = b ans += 1 elif b < 2 * (a - f): flag = 1 break p -= 2 * (a - f) direct = "n" elif direct == "n": if p < 2 * f and b >= 2 * f: p = b ans += 1 elif b < 2 * f: flag = 1 break p -= 2 * f direct = "p" k -= 1 if p < 0: flag = 1 break if flag == 1: print(-1) else: print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR STRING IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR STRING IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR STRING IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR STRING IF VAR STRING IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) req = 0 live_fuel = b while k > 0: live_fuel -= f k -= 1 if live_fuel < 0: req = -1 break else: if live_fuel >= 2 * (a - f) or k == 0 and live_fuel >= a - f: live_fuel -= a - f else: live_fuel = b req += 1 live_fuel -= a - f if live_fuel < 0: req = -1 break else: if k <= 0: break k -= 1 live_fuel -= a - f if live_fuel < 0: req = -1 break else: if live_fuel >= 2 * f or k == 0 and live_fuel >= f: live_fuel -= f else: live_fuel = b - f req += 1 if live_fuel < 0: req = -1 break print(req)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) r, p, s, t = 0, b - f, 1, [2 * f, 2 * (a - f)] if p < 0: r -= 1 else: for i in range(k - 1): if p < t[s]: p = b r += 1 if p < t[s]: r = -1 break p -= t[s] s = 1 - s if t[s] // 2 > p: r += 1 if t[s] // 2 > b: r = -1 print(r)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER LIST BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) cur = b good = 1 cnt = 0 for i in range(k): if i % 2 == 0: if i == k - 1: if cur < f: good = 0 elif cur >= a: cur -= a cnt += 0 elif b >= a - f: cnt += 1 else: good = 0 elif 2 * (a - f) > b: good = 0 elif cur >= 2 * a - f: cnt += 0 cur -= a elif cur < f: good = 0 else: cnt += 1 cur = b - (a - f) elif i == k - 1: if cur < a - f: good = 0 elif cur >= a: cur -= a cnt += 0 elif b >= f: cnt += 1 else: good = 0 elif 2 * f > b: good = 0 elif cur >= a + f: cur -= a cnt += 0 elif cur < a - f: good = 0 else: cnt += 1 cur = b - f if good == 1: print(cnt) else: print(-1)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = [int(i) for i in input().split(" ")] x = f y = a - f oil = b result = 0 alert = 0 if k == 1: oil -= x if oil < 0: alert = 1 if oil < y: result += 1 oil = b oil -= y if oil < 0: alert = 1 else: oil -= x if oil < 0: alert = 1 if oil < 2 * y: result += 1 oil = b if k == 2: oil -= 2 * y if oil < 0: alert = 1 if oil < x: result += 1 oil = b else: oil -= 2 * y if oil < 0: alert = 1 if oil < 2 * x: result += 1 oil = b if k > 2: k -= 2 for ii in range(int((k - 1) / 2)): oil -= 2 * x if oil < 0: alert = 1 if oil < 2 * y: oil = b result += 1 k -= 1 oil -= 2 * y if oil < 0: alert = 1 if oil < 2 * x: oil = b result += 1 k -= 1 if k == 1: oil -= 2 * x if oil < 0: alert = 1 if oil < y: oil = b result += 1 if k == 2: oil -= 2 * x if oil < 0: alert = 1 if oil < 2 * y: oil = b result += 1 oil -= 2 * y if oil < x: oil = b result += 1 if alert == 1: print(-1) else: print(result)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) x = 0 g = b for kk in range(k - 1): if kk % 2 == 0: d = a + (a - f) if g < d: if g < f: x = -1 break x += 1 g = b - (a - f) if g < 0: x = -1 break else: g -= a else: d = a + f if g < d: if g < a - f: x = -1 break x += 1 g = b - f if g < 0: x = -1 break else: g -= a if (k - 1) % 2 == 0: if g < a: if g < f: x = -1 else: x += 1 g = b - (a - f) if g < 0: x = -1 elif g < a: if g < a - f: x = -1 else: x += 1 g = b - f if g < 0: x = -1 print(x)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) if b < f or b < a - f: print(-1) exit() com = b // a ca = b % a poi = com % 2 ans = 0 t = 0 while com < k: t += 1 if poi == 0: if ca < f: ca = b - f ans += 1 else: ca = b - a + f ans += 1 com += 1 elif ca < a - f: ca = b - a + f ans += 1 else: ca = b - f ans += 1 com += 1 com += ca // a ca = ca % a poi = com % 2 if t > 1000000: print(-1) exit() print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = input().split() a = int(a) b = int(b) f = int(f) k = int(k) i = 0 j = 1 fill = 0 store = b direct = 1 while j <= k: if i == 0: n = f direct = 1 if j > 1: store -= abs(f) elif i == a: n = f direct = 0 store -= abs(f - a) elif direct == 0: n = 0 store -= abs(f - a) else: n = a store -= abs(f) if store < 0: fill = -1 break if i == f: if store < 2 * abs(n - i) and j < k: fill += 1 store = b elif store < abs(n - i) and j == k: fill += 1 store = b if b < abs(n - i): fill = -1 break if n == 0 or n == a: j += 1 i = n print(fill)
ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def solution(a, b, f, k): d1 = 2 * (a - f) d2 = 2 * f if k == 1: if f > b or a - f > b: return -1 elif k == 2: if f > b or d1 > b: return -1 elif d1 > b or d2 > b: return -1 fuels = 0 fue = b - f for i in range(k - 1): dist = d1 if i % 2 == 0 else d2 if fue < dist: fuels += 1 fue = b fue -= dist dist = a - f if (k - 1) % 2 == 0 else f if fue < dist: fuels += 1 return fuels a, b, f, k = map(int, input().split()) print(solution(a, b, f, k))
FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
l = list(map(int, input().split())) a, fuel, f, k = l[0], l[1], l[2], l[3] i = 1 b = fuel c = 0 flag = 0 while i < k: if i % 2 != 0: if b >= 2 * a - f: b -= a elif b >= f: b = fuel - (a - f) c += 1 else: print("-1") flag = 1 break elif b >= a + f: b -= a elif b >= a - f: b = fuel - f c += 1 else: print("-1") flag = 1 break i += 1 if flag == 0: if k % 2 == 0: if b >= a: b -= a elif b >= a - f and fuel >= f: c += 1 else: flag = 1 print("-1") elif b >= a: b -= a elif b >= f and fuel >= a - f: c += 1 else: flag = 1 print("-1") if flag == 0: print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
def impossible(): print(-1) exit() dest, cap, station, journey = map(int, input().strip().split()) left, right = 2 * station, 2 * (dest - station) if journey == 1 and (cap < station or cap < dest - station): impossible() if journey == 2 and (cap < station or cap < right): impossible() if journey >= 3 and (cap < left or cap < right): impossible() time = 0 consume = station for i in range(journey - 1): go = left if i & 1 else right if consume + go > cap: time += 1 consume = go else: consume += go if ( journey & 1 == 0 and consume + station > cap or journey & 1 and consume + dest - station > cap ): print(time + 1) else: print(time)
FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
init = list(map(int, input().split())) finalPoint = init[0] fuelCapacity = init[1] refuelPoint = init[2] voyageCount = init[3] currentVoyageCount = 0 currentFuelCapacity = fuelCapacity currentPosition = 0 refuelCount = 0 isEnd = False error = False stepSide = 1 def isHaveToRefuel(): global currentFuelCapacity global refuelCount if currentVoyageCount + 1 == voyageCount: if stepSide == 1: if currentFuelCapacity >= finalPoint - refuelPoint: return else: currentFuelCapacity = fuelCapacity refuelCount += 1 elif currentFuelCapacity >= refuelPoint - 0: return else: currentFuelCapacity = fuelCapacity refuelCount += 1 elif stepSide == 1: if currentFuelCapacity >= (finalPoint - refuelPoint) * 2: return else: currentFuelCapacity = fuelCapacity refuelCount += 1 elif currentFuelCapacity >= (refuelPoint - 0) * 2: return else: currentFuelCapacity = fuelCapacity refuelCount += 1 def makeStep(): global currentPosition global currentFuelCapacity global error if currentPosition == refuelPoint: isHaveToRefuel() if stepSide == 1: currentFuelCapacity = currentFuelCapacity - (finalPoint - refuelPoint) currentPosition = finalPoint else: currentFuelCapacity = currentFuelCapacity - (refuelPoint - 0) currentPosition = 0 elif stepSide == 1: currentFuelCapacity = currentFuelCapacity - (refuelPoint - 0) currentPosition = refuelPoint else: currentFuelCapacity = currentFuelCapacity - (finalPoint - refuelPoint) currentPosition = refuelPoint if currentFuelCapacity < 0: error = True while currentVoyageCount < voyageCount: makeStep() if error == True: isEnd = False break if currentPosition == 0 or currentPosition == finalPoint: currentVoyageCount += 1 if currentPosition == 0: stepSide = 1 elif currentPosition == finalPoint: stepSide = -1 if currentVoyageCount == voyageCount: isEnd = True if isEnd == True: print(refuelCount) else: print("-1")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN ASSIGN VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = tuple([int(i) for i in input().split(" ")]) pos = True route = 0 petrol = 0 if abs(f) > b: print(-1) else: tank = b need = abs(f) for i in range(k + 1): tank -= need route += need if i % 2 == 1: need = abs(f) * 2 else: need = abs(a - f) * 2 if route + need > a * k: need = a * k - route if need > b: pos = False break elif need > tank: petrol += 1 tank = b if pos: print(petrol) else: print(-1)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = [int(i) for i in input().split()] ff = [0] for i in range(k): d = f if i % 2 == 1: d = a - f ff.append(i * a + d) ff.append(k * a) stops = 0 while len(ff) > 0: next = 0 if ff[0] == k * a: break while ff[next + 1] - ff[0] <= b: next += 1 if ff[next] == k * a: break if next == 0: print("-1") return if ff[next] != k * a: stops += 1 while next > 0: ff.pop(0) next -= 1 else: break print(stops)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR BIN_OP VAR VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys DEBUG = False a, b, f, k = map(int, input().split()) def game_over(): print(-1) sys.exit() fuel = b add_fuel_count = 0 fuel_on_next_stop = fuel - f if fuel_on_next_stop < 0: game_over() distance = 0 for i in range(1, k + 1): fuel = fuel_on_next_stop if DEBUG: print("i= {} : ".format(i)) print("\t fuel_on_station = {} ".format(fuel)) if i == k: if i % 2: distance = a - f else: distance = f elif i % 2: distance = 2 * (a - f) else: distance = 2 * f if fuel < distance: fuel, add_fuel_count = b, add_fuel_count + 1 fuel_on_next_stop = fuel - distance if fuel_on_next_stop < 0: game_over() if DEBUG: print("\t distance = {} ".format(distance)) print("\t fuel_on_next_stop = {} ".format(fuel_on_next_stop)) if fuel == b: print("\t YES") print(add_fuel_count)
IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
l = [int(x) for x in input().split()] a = [] b = l[1] f = 0 c = 0 a.append(0) for i in range(l[3]): if i % 2 == 0: a.append(i * l[0] + l[2]) else: a.append((i + 1) * l[0] - l[2]) a.append(l[0] * l[3]) for j in range(1, l[3] + 2): if b >= a[j] - a[j - 1]: b = b - a[j] b = b + a[j - 1] else: b = l[1] if b >= a[j] - a[j - 1]: f = f + 1 b = b - (a[j] - a[j - 1]) else: c = -1 break if c == -1: print(c) else: print(f)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = [int(x) for x in input().split()] curpos = 0 possible = True gas = b refuelCount = 0 def dis(a, b): return abs(a - b) while k > 0: if dis(curpos, f) > gas: possible = False break dis_to_edge = dis(f, 0) if curpos == a else dis(f, a) if k > 1 and dis(curpos, f) + dis_to_edge * 2 > gas: gas -= dis(curpos, f) if gas < 0: possible = False break gas = b refuelCount += 1 gas -= dis_to_edge if gas < 0: possible = False break curpos = a - curpos elif k > 1: curpos = a - curpos gas -= a if gas < 0: possible = False break elif gas >= a: curpos = a - curpos gas -= a elif dis(curpos, f) <= gas: refuelCount += 1 curpos = a - curpos gas = b gas -= dis(curpos, f) if gas < 0: possible = False break else: possible = False break if curpos == 0 or curpos == a: k -= 1 if possible: print(refuelCount) else: print(-1)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR WHILE VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) fuel_count = 0 fuel = b i = 0 fuel -= f if fuel < 0: print(-1) exit(0) while True: if fuel >= a - f and i + 1 == k: break if b >= a - f and i + 1 == k: fuel_count += 1 break elif fuel < 2 * (a - f): fuel = b fuel_count += 1 if fuel < 2 * (a - f): print(-1) exit(0) fuel -= 2 * (a - f) i += 1 if i == k: break if fuel >= f and i + 1 == k: break if b >= f and i + 1 == k: fuel_count += 1 break elif fuel < 2 * f: fuel = b fuel_count += 1 if fuel < 2 * f: print(-1) exit(0) fuel -= 2 * f i += 1 if i == k: break print(fuel_count)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().strip().split()) st = 0 mod = 0 fue = b flg = 0 ans = 0 if fue < f: flg = 1 fue -= f mod = 1 for i in range(k): if st == 0: if mod == 0: mod = 1 if fue < f: fue = b ans += 1 if fue < f: flg = 1 break fue -= f else: st = 1 mod = 1 if i == k - 1: if fue < a - f: fue = b ans += 1 if fue < a - f: flg = 1 break fue -= a - f continue if fue < 2 * (a - f): fue = b ans += 1 if fue < 2 * (a - f): flg = 1 break fue -= 2 * (a - f) else: st = 0 mod = 1 if i == k - 1: if fue < f: fue = b ans += 1 if fue < f: flg = 1 break fue -= f continue if fue < 2 * f: fue = b ans += 1 if fue < 2 * f: flg = 1 break fue -= 2 * f if flg == 1: print(-1) else: print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) curr, res = b, 0 for i in range(k): prev = curr curr -= a if i % 2 == 0: if curr < a - f and i < k - 1 or curr < 0: curr = b - a + f res += 1 if curr < a - f and i < k - 1 or curr < 0 or prev < f: print(-1) exit() elif curr < f and i < k - 1 or curr < 0: curr = b - f res += 1 if curr < f and i < k - 1 or curr < 0 or prev < a - f: print(-1) exit() print(res)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
R = lambda: list(map(int, input().split())) a, b, f, k = R() p = b s = 0 if k == 1: if f > b or a - f > b: print(-1) elif b >= a: print(0) else: print(1) elif k == 2: if b < 2 * (a - f) or b < f: print(-1) elif b >= 2 * a: print(0) elif b >= a + a - f: print(1) elif b >= a + f: print(1) else: print(2) elif b < 2 * (a - f) or b < 2 * f: print(-1) else: for i in range(k): if i == k - 1: if b < a: s += 1 elif i % 2 == 0: if b >= a + a - f: b -= a else: s += 1 b = p - (a - f) elif b >= a + f: b -= a else: b = p - f s += 1 print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
import sys def solve(): end, full, real_mid, times = map(int, sys.stdin.readline().split()) oil = full cnt = 0 for i in range(times): if i % 2 == 0: mid = real_mid else: mid = end - real_mid if mid > oil: return -1 oil -= mid if i != times - 1: if (end - mid) * 2 > full: return -1 if (end - mid) * 2 > oil: oil = full cnt += 1 else: if end - mid > full: return -1 if end - mid > oil: oil = full cnt += 1 oil -= end - mid return cnt print(solve())
IMPORT FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) reFills = 0 journeys = 0 fuel = b - f def nextStop(): if journeys % 2 == 0: if journeys == k - 1: return a - f return (a - f) * 2 else: if journeys == k - 1: return f return f * 2 if fuel < 0: print(-1) else: while journeys < k: next_stop = nextStop() if fuel < next_stop: reFills += 1 fuel = b fuel -= next_stop if fuel < 0: reFills = -1 break journeys += 1 print(reFills)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) t = 0 lt = b ans = 0 while t < k: if t & 1: lt -= a - f if lt < 0: exit(print(-1)) if lt < f * 2: ans += 1 if t == k - 1 and lt >= f: ans -= 1 lt = b lt -= f if lt < 0: exit(print(-1)) else: lt -= f if lt < 0: exit(print(-1)) if lt < (a - f) * 2: ans += 1 if t == k - 1 and lt >= a - f: ans -= 1 lt = b lt -= a - f if lt < 0: exit(print(-1)) t += 1 print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys. The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank. There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline. What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0. -----Input----- The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. -----Output----- Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1. -----Examples----- Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 -----Note----- In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
a, b, f, k = map(int, input().split()) d = 1 now = 0 res = 0 k += 1 g = b bb = b a, b = 0, a while True: if now == a or now == b: k -= 1 g -= abs(now - f) now = f if not k or g < 0: break elif now == f: c = b - f if d else f dis = c if k == 1 else 2 * c if g >= dis: g -= c now = b if d else a d ^= 1 elif bb < dis: break else: g = bb res += 1 print(-1 if k else res)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR