description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Output : 7 Explanation : 3rd smallest element in the given array is 7. Example 2: Input: N = 5 arr[] = 7 10 4 20 15 K = 4 Output : 15 Explanation : 4th smallest element in the given array is 15. Your Task: You don't have to read input or print anything. Your task is to complete the function kthSmallest() which takes the array arr[], integers l and r denoting the starting and ending index of the array and an integer K as input and returns the K^{th} smallest element. Expected Time Complexity: O(n) Expected Auxiliary Space: O(log(n)) Constraints: 1 <= N <= 10^{5} 1 <= arr[i] <= 10^{5} 1 <= K <= N
class Solution: def kthSmallest(self, arr, l, r, k): l = arr[0] arr.reverse() r = arr[0] arr.sort() asf = arr[k - 1] return asf
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Output : 7 Explanation : 3rd smallest element in the given array is 7. Example 2: Input: N = 5 arr[] = 7 10 4 20 15 K = 4 Output : 15 Explanation : 4th smallest element in the given array is 15. Your Task: You don't have to read input or print anything. Your task is to complete the function kthSmallest() which takes the array arr[], integers l and r denoting the starting and ending index of the array and an integer K as input and returns the K^{th} smallest element. Expected Time Complexity: O(n) Expected Auxiliary Space: O(log(n)) Constraints: 1 <= N <= 10^{5} 1 <= arr[i] <= 10^{5} 1 <= K <= N
class Solution: def kthSmallest(self, arr, l, r, k): def count_smaller(mid_el, arr): count_sm = 0 for i in arr: if i < mid_el: count_sm += 1 return count_sm l = min(arr) h = max(arr) ans = 0 while l <= h: mid = l + (h - l) // 2 if count_smaller(mid, arr) >= k - 1: ans = mid h = mid - 1 else: l = mid + 1 temp = ans diff = abs(ans - max(arr)) for el in arr: temp_diff = abs(ans - el) if el == ans: return ans elif ans < el and diff >= temp_diff: temp = el diff = temp_diff return temp
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Output : 7 Explanation : 3rd smallest element in the given array is 7. Example 2: Input: N = 5 arr[] = 7 10 4 20 15 K = 4 Output : 15 Explanation : 4th smallest element in the given array is 15. Your Task: You don't have to read input or print anything. Your task is to complete the function kthSmallest() which takes the array arr[], integers l and r denoting the starting and ending index of the array and an integer K as input and returns the K^{th} smallest element. Expected Time Complexity: O(n) Expected Auxiliary Space: O(log(n)) Constraints: 1 <= N <= 10^{5} 1 <= arr[i] <= 10^{5} 1 <= K <= N
class Solution: def kthSmallest(self, arr, l, r, k): return self.kthSmallestUtil(arr, l, r, k - 1) def partition(self, arr, low, high): pivot_index = random.randint(low, high) arr[pivot_index], arr[high] = arr[high], arr[pivot_index] i = low for j in range(low, high): if arr[j] < arr[high]: arr[i], arr[j] = arr[j], arr[i] i += 1 arr[i], arr[high] = arr[high], arr[i] return i def kthSmallestUtil(self, arr, l, r, k): if l == r: return arr[l] pivot_index = self.partition(arr, l, r) if k == pivot_index: return arr[k] elif k < pivot_index: return self.kthSmallestUtil(arr, l, pivot_index - 1, k) else: return self.kthSmallestUtil(arr, pivot_index + 1, r, k)
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for i in range(t): d = {} for i in range(12): a, b, c, p, e = map(str, input().split()) b, p = int(b), int(p) if a not in d: d[a] = [0, 0] if e not in d: d[e] = [0, 0] if b > p: d[a][0] += 3 d[a][1] += b - p d[e][1] -= b - p elif p > b: d[e][0] += 3 d[e][1] += p - b d[a][1] -= p - b else: d[a][0] += 1 d[e][0] += 1 d = sorted(d, key=d.get) print(d[3], d[2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
def tableToppers(scoreBoard): sorted_dict = {} sorted_keys = sorted(scoreBoard, key=scoreBoard.get) for w in sorted_keys: sorted_dict[w] = scoreBoard[w] print(list(sorted_dict)[-1], "", list(sorted_dict)[-2]) def updateTeam(scoreBoard, Name, Goals, Conceded): if Name not in scoreBoard.keys(): list1 = [] if Goals > Conceded: list1.append(3) elif Goals == Conceded: list1.append(1) else: list1.append(0) scoreBoard[Name] = list1 list1.append(Goals - Conceded) else: scoreBoard[Name][1] += Goals - Conceded if Goals > Conceded: scoreBoard[Name][0] += 3 elif Goals == Conceded: scoreBoard[Name][0] += 1 for _ in range(int(input())): scoreBoard = {} for i in range(12): HName, HGoals, vs, AGoals, AName = input().split() updateTeam(scoreBoard, HName.strip(), int(HGoals), int(AGoals)) updateTeam(scoreBoard, AName.strip(), int(AGoals), int(HGoals)) tableToppers(scoreBoard)
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for i in range(int(input())): d = dict() for j in range(12): l = input().split() l.remove("vs.") if l[0] in d: if int(l[1]) > int(l[2]): d[l[0]] = d[l[0]][0] + 3, d[l[0]][1] + int(l[1]) - int(l[2]) elif int(l[1]) < int(l[2]): d[l[0]] = d[l[0]][0], d[l[0]][1] + int(l[1]) - int(l[2]) else: d[l[0]] = d[l[0]][0] + 1, d[l[0]][1] + int(l[1]) - int(l[2]) elif l[0] not in d: if int(l[1]) > int(l[2]): d[l[0]] = 3, int(l[1]) - int(l[2]) elif int(l[1]) < int(l[2]): d[l[0]] = 0, int(l[1]) - int(l[2]) else: d[l[0]] = 1, int(l[1]) - int(l[2]) if l[3] in d: if int(l[2]) > int(l[1]): d[l[3]] = d[l[3]][0] + 3, d[l[3]][1] + int(l[2]) - int(l[1]) elif int(l[2]) < int(l[1]): d[l[3]] = d[l[3]][0], d[l[3]][1] + int(l[2]) - int(l[1]) else: d[l[3]] = d[l[3]][0] + 1, d[l[3]][1] + int(l[2]) - int(l[1]) elif l[3] not in d: if int(l[2]) > int(l[1]): d[l[3]] = 3, int(l[2]) - int(l[1]) elif int(l[1]) > int(l[2]): d[l[3]] = 0, int(l[2]) - int(l[1]) else: d[l[3]] = 1, int(l[2]) - int(l[1]) l = list() for k, v in d.items(): l.append((v, k)) l.sort() print(l[-1][1], l[-2][1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for i in range(t): l = [] for j in range(12): y = input() x = y.split() l.append(x) d = {} for j in range(12): if l[j][0] not in d: d[l[j][0]] = 0 else: continue dg = d.copy() for j in range(12): if int(l[j][1]) > int(l[j][-2]): d[l[j][0]] += 3 elif l[j][1] == l[j][-2]: d[l[j][0]] += 1 d[l[j][-1]] += 1 else: d[l[j][-1]] += 3 for j in range(12): val = int(l[j][1]) - int(l[j][-2]) dg[l[j][0]] += val val1 = int(l[j][-2]) - int(l[j][1]) dg[l[j][-1]] += val1 fl = [] for i in d.keys(): fl.append([d[i], dg[i], i]) fl.sort(reverse=True) print(fl[0][2], fl[1][2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
n = int(input()) for i in range(0, n): d = {} d2 = {} for j in range(0, 12): s = input() s = s.split(" ") if int(s[1]) > int(s[3]): if s[0] in d.keys(): d[s[0]] += 3 else: d[s[0]] = 3 if s[0] in d2.keys(): d2[s[0]] += int(s[1]) - int(s[3]) else: d2[s[0]] = int(s[1]) - int(s[3]) if s[4] in d2.keys(): d2[s[4]] -= int(s[1]) - int(s[3]) else: d2[s[4]] = -(int(s[1]) - int(s[3])) elif int(s[1]) < int(s[3]): if s[4] in d.keys(): d[s[4]] += 3 else: d[s[4]] = 3 if s[4] in d2.keys(): d2[s[4]] += int(s[3]) - int(s[1]) else: d2[s[4]] = int(s[3]) - int(s[1]) if s[0] in d2.keys(): d2[s[0]] -= int(s[3]) - int(s[1]) else: d2[s[0]] = -(int(s[3]) - int(s[1])) elif int(s[1]) == int(s[3]): if s[0] in d.keys(): d[s[0]] += 1 else: d[s[0]] = 1 if s[4] in d.keys(): d[s[4]] += 1 else: d[s[4]] = 1 st = "" for l in range(0, 2): max = 0 win = "" for k in d.keys(): if d[k] > max: max = d[k] win = k elif d[k] == max: if d2[k] > d2[win]: max = d[k] win = k st = st + " " + win del d[win] del d2[win] print(st.strip())
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for _ in range(t): dic = {} for i in range(12): t1, g1, vs, g2, t2 = input().split() g1, g2 = int(g1), int(g2) if g1 > g2: if t1 not in dic: dic[t1] = [3, g1 - g2] else: dic[t1][0] += 3 dic[t1][1] += g1 - g2 if t2 not in dic: dic[t2] = [0, g2 - g1] else: dic[t2][1] += g2 - g1 elif g2 > g1: if t1 not in dic: dic[t1] = [0, g1 - g2] else: dic[t1][1] += g1 - g2 if t2 not in dic: dic[t2] = [3, g2 - g1] else: dic[t2][0] += 3 dic[t2][1] += g2 - g1 else: if t1 not in dic: dic[t1] = [1, 0] else: dic[t1][0] += 1 if t2 not in dic: dic[t2] = [1, 0] else: dic[t2][0] += 1 arr = [] for i in range(2): temp, win, gd = 0, "2", -1000000 for ele in dic: if dic[ele][0] > temp: temp = dic[ele][0] win = ele gd = dic[ele][1] elif dic[ele][0] == temp: if dic[ele][1] > gd: win = ele gd = dic[ele][1] arr.append(win) del dic[win] for ele in arr: print(ele, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): di = {} for i in range(12): a = input() arr = a.split(" ") if arr[0] not in di: di[arr[0]] = 0 if arr[-1] not in di: di[arr[-1]] = 0 if int(arr[1]) > int(arr[3]): di[arr[0]] += 3000 elif int(arr[1]) < int(arr[3]): di[arr[-1]] += 3000 else: di[arr[0]] += 1000 di[arr[-1]] += 1000 di[arr[-1]] += int(arr[3]) - int(arr[1]) di[arr[0]] += int(arr[1]) - int(arr[3]) sortedaa = sorted(di.items(), key=lambda x: x[1], reverse=True) print(sortedaa[0][0], sortedaa[1][0])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
n = int(input()) for i in range(n): d = {} gd = {} for i in range(12): ar = list(map(str, input().split(" "))) t1 = ar[0] t2 = ar[4] v1 = int(ar[1]) v2 = int(ar[3]) if v1 > v2: if t1 in d: d[t1] += 3 else: d[t1] = 3 if t1 in gd: gd[t1] += v1 - v2 else: gd[t1] = v1 - v2 if t2 in gd: gd[t2] += v2 - v1 else: gd[t2] = v2 - v1 elif v2 > v1: if t2 in d: d[t2] += 3 else: d[t2] = 3 if t2 in gd: gd[t2] += v2 - v1 else: gd[t2] = v2 - v1 if t1 in gd: gd[t1] += v1 - v2 else: gd[t1] = v1 - v2 else: if t1 in d: d[t1] += 1 else: d[t1] = 1 if t2 in d: d[t2] += 1 else: d[t2] = 1 l = [] for i in d.keys(): l.append([d[i], gd[i], i]) l.sort(reverse=True) print(l[0][2], l[1][2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
n = int(input()) for i in range(0, n): d = {} for j in range(0, 12): s = input() s = s.split(" ") if int(s[1]) > int(s[3]): if s[0] in d.keys(): d[s[0]][0] += 3 d[s[0]][1] += int(s[1]) - int(s[3]) else: d[s[0]] = [3, int(s[1]) - int(s[3])] if s[4] in d.keys(): d[s[4]][1] -= int(s[1]) - int(s[3]) else: d[s[4]] = [0, -(int(s[1]) - int(s[3]))] elif int(s[1]) < int(s[3]): if s[4] in d.keys(): d[s[4]][0] += 3 d[s[4]][1] += int(s[3]) - int(s[1]) else: d[s[4]] = [3, int(s[3]) - int(s[1])] if s[0] in d.keys(): d[s[0]][1] -= int(s[3]) - int(s[1]) else: d[s[0]] = [0, -(int(s[3]) - int(s[1]))] elif int(s[1]) == int(s[3]): if s[0] in d.keys(): d[s[0]][0] += 1 else: d[s[0]] = [1, 0] if s[4] in d.keys(): d[s[4]][0] += 1 else: d[s[4]] = [1, 0] d = sorted(d, key=d.get, reverse=True) print(d[0], d[1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): xd = {} for _ in range(12): x, xx, _, yy, y = input().split() if x not in xd: xd[x] = [0, 0] if y not in xd: xd[y] = [0, 0] xx, yy = int(xx), int(yy) if xx > yy: xd[x][0] += 3 xd[x][1] += xx - yy xd[y][1] -= xx - yy elif xx == yy: xd[x][0] += 1 xd[y][0] += 1 elif xx < yy: xd[y][0] += 3 xd[y][1] += yy - xx xd[x][1] -= yy - xx xd = sorted(xd.items(), key=lambda item: item[1], reverse=True) print(xd[0][0], xd[1][0])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) while t: t -= 1 pnts, gldif = {}, {} for i in range(12): ls = list(input().split()) nm1, gl1, vs, gl2, nm2 = ls[0], int(ls[1]), ls[2], int(ls[3]), ls[4] if nm1 not in pnts: if gl1 > gl2: pnts[nm1] = 3 elif gl2 > gl1: pnts[nm1] = 0 else: pnts[nm1] = 1 elif gl1 > gl2: pnts[nm1] += 3 elif gl2 > gl1: pnts[nm1] += 0 else: pnts[nm1] += 1 if nm2 not in pnts: if gl2 > gl1: pnts[nm2] = 3 elif gl1 > gl2: pnts[nm2] = 0 else: pnts[nm2] = 1 elif gl2 > gl1: pnts[nm2] += 3 elif gl1 > gl2: pnts[nm2] += 0 else: pnts[nm2] += 1 if nm1 not in gldif: gldif[nm1] = gl1 - gl2 else: gldif[nm1] += gl1 - gl2 if nm2 not in gldif: gldif[nm2] = gl2 - gl1 else: gldif[nm2] += gl2 - gl1 fin_ls = [] pkeys = list(pnts.keys()) pval = list(pnts.values()) for i in range(len(pnts)): fin_ls.append([pnts[pkeys[i]], gldif[pkeys[i]], pkeys[i]]) fin_ls.sort(reverse=True) print(*[fin_ls[0][2], fin_ls[1][2]])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for i in range(int(input())): d = {} for j in range(12): str = input() l = str.split() team1 = l[0] team2 = l[4] x = int(l[1]) y = int(l[3]) t1 = [] t2 = [] if team1 not in d.keys(): d[team1] = [0, 0] if team2 not in d.keys(): d[team2] = [0, 0] if x > y: d[team1][0] += 3 elif y > x: d[team2][0] += 3 else: d[team1][0] += 1 d[team2][0] += 1 d[team1][1] += x - y d[team2][1] += y - x sort_sict = sorted(d.items(), key=lambda x: (x[1][0], x[1][1]), reverse=True) j = 0 print(sort_sict[j][0], sort_sict[j + 1][0])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for _ in range(t): dct = {} for i in range(12): lst = list(input().split()) goal_home_team, goal_away_team = int(lst[1]), int(lst[-2]) home_team, away_team = lst[0], lst[-1] points_home_team, points_away_team = 0, 0 if goal_home_team > goal_away_team: points_home_team = 3 elif goal_home_team < goal_away_team: points_away_team = 3 else: points_home_team, points_away_team = 1, 1 if home_team not in dct: dct[home_team] = [points_home_team, goal_home_team - goal_away_team] else: team_data = dct[home_team] team_data[0] += points_home_team team_data[1] += goal_home_team - goal_away_team if away_team not in dct: dct[away_team] = [points_away_team, goal_away_team - goal_home_team] else: team_data = dct[away_team] team_data[0] += points_away_team team_data[1] += goal_away_team - goal_home_team final_lst = [(dct[ele] + [ele]) for ele in dct] final_lst.sort(reverse=True) print(final_lst[0][-1], final_lst[1][-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for _ in range(t): di = {} for i in range(12): t1, s1, v, s2, t2 = map(str, input().split()) if t1 not in di: di[t1] = [0, 0] if t2 not in di: di[t2] = [0, 0] s1 = int(s1) s2 = int(s2) if s1 > s2: di[t1][0] += 3 di[t1][1] += s1 - s2 di[t2][1] += s2 - s1 if s2 > s1: di[t2][0] += 3 di[t2][1] += s2 - s1 di[t1][1] += s1 - s2 if s1 == s2: di[t1][0] += 1 di[t2][0] += 1 fa = [] for i in di.keys(): fa.append([di[i][0], di[i][1], i]) fa.sort(reverse=True) print(fa[0][2], fa[1][2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for i in range(t): names = [] scores = [0] * 4 diff = [0] * 4 for j in range(12): name1, goals1, bb, goals2, name2 = input().split() goals1 = int(goals1) goals2 = int(goals2) if name1 not in names: names.append(name1) if name2 not in names: names.append(name2) if goals1 > goals2: scores[names.index(name1)] += 3 elif goals2 > goals1: scores[names.index(name2)] += 3 else: scores[names.index(name1)] += 1 scores[names.index(name2)] += 1 diff[names.index(name1)] += goals1 - goals2 diff[names.index(name2)] += goals2 - goals1 res = [] for j in range(4): res.append([scores[j], diff[j], names[j]]) res.sort() print(res[-1][-1], res[-2][-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
T = int(input()) for _ in range(T): points = {} for i in range(12): l = input().split(" ") scoreA = int(l[1]) scoreB = int(l[3]) if scoreA > scoreB: pointsA, pointsB = 3, 0 elif scoreA < scoreB: pointsA, pointsB = 0, 3 else: pointsA, pointsB = 1, 1 c = points.get(l[0], [0, 0]) points[l[0]] = [c[0] + pointsA, c[1] + scoreA - scoreB] c = points.get(l[-1], [0, 0]) points[l[-1]] = [c[0] + pointsB, c[1] + scoreB - scoreA] scores = [(a, b) for b, a in points.items()] scores.sort() print(scores[-1][1], scores[-2][1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER LIST BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER LIST BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): d = {} for i in range(12): a, b, c, d1, e = map(str, input().split(" ")) if a not in d: d[a] = [0, 0] if e not in d: d[e] = [0, 0] b = int(b) d1 = int(d1) if b > d1: d[a][0] += 3 elif b < d1: d[e][0] += 3 elif b == d1: d[a][0] += 1 d[e][0] += 1 d[a][1] += b - d1 d[e][1] += d1 - b ans = [] for i in d: ans.append([d[i][0], d[i][1], i]) ans = sorted(ans, reverse=True) print(ans[0][2], ans[1][2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
test_cases = int(input()) def pointstable(team1detail, team2detail, table): if team1detail[0] not in table: table.append(team1detail[0]) pointtable[team1detail[0]] = [0, 0] else: pass if team2detail[1] not in table: table.append(team2detail[1]) pointtable[team2detail[1]] = [0, 0] else: pass team1goal = int(team1detail[1].strip()) team2goal = int(team2detail[0].strip()) if team1goal > team2goal: pointtable[team1detail[0]][0] += 3 pointtable[team1detail[0]][1] += team1goal - team2goal pointtable[team2detail[1]][1] += team2goal - team1goal elif team1goal == team2goal: pointtable[team1detail[0]][0] += 1 pointtable[team2detail[1]][0] += 1 else: pointtable[team2detail[1]][0] += 3 pointtable[team1detail[0]][1] += team1goal - team2goal pointtable[team2detail[1]][1] += team2goal - team1goal def result(matchdetail, table): team1 = matchdetail[0].strip() team2 = matchdetail[1].strip() team1detail = team1.split(" ") team2detail = team2.split(" ") pointstable(team1detail, team2detail, table) for i in range(test_cases): table = [] pointtable = {} for matches in range(12): inp = input().split("vs.") result(inp, table) sorted_table = {} sorted_points = sorted(pointtable, key=pointtable.get) for w in sorted_points: sorted_table[w] = pointtable[w] listoftabletop = [] for key in sorted_table.keys(): listoftabletop.append(key) print(listoftabletop[3], listoftabletop[2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): d = {} for i in range(12): l = [] l = list(map(str, input().split())) if l[0] not in d: d[l[0]] = [0, 0] if l[-1] not in d: d[l[-1]] = [0, 0] if int(l[1]) > int(l[3]): d[l[0]][0] += 3 elif int(l[1]) < int(l[3]): d[l[-1]][0] += 3 else: d[l[0]][0] += 1 d[l[-1]][0] += 1 d[l[0]][1] += int(l[1]) - int(l[3]) d[l[-1]][1] += int(l[3]) - int(l[1]) ans = [] for i in d: ans.append([d[i][0], d[i][1], i]) ans.sort(reverse=True) print(ans[0][2], ans[1][2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for _ in range(t): matches = [] pt = {} for i in range(12): t1, s1, vs, s2, t2 = input().split() s1 = int(s1) s2 = int(s2) if t1 not in pt: pt[t1] = [0, 0] if t2 not in pt: pt[t2] = [0, 0] if s1 > s2: pt[t1][0] += 3 elif s1 < s2: pt[t2][0] += 3 else: pt[t1][0] += 1 pt[t2][0] += 1 pt[t1][1] += s1 - s2 pt[t2][1] += s2 - s1 table = [] for i in pt: table.append([pt[i][0], pt[i][1], i]) table.sort(reverse=True) print(table[0][2], table[1][2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) for _ in range(t): n = 12 d = {} for _ in range(n): teamA, teamB = input().split(" vs. ") teamA = teamA.split() teamB = teamB.split() if teamA[0] not in d: d.update({teamA[0]: [0, 0]}) if teamB[1] not in d: d.update({teamB[1]: [0, 0]}) goalA = int(teamA[1]) - int(teamB[0]) goalB = int(teamB[0]) - int(teamA[1]) d[teamA[0]][1] += goalA d[teamB[1]][1] += goalB if goalA > goalB: d[teamA[0]][0] += 3 elif goalB > goalA: d[teamB[1]][0] += 3 else: d[teamA[0]][0] += 1 d[teamB[1]][0] += 1 result = sorted(d, key=d.get) print(result[-1], result[-2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR DICT VAR NUMBER LIST NUMBER NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR DICT VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): a = {} for i in range(12): b, c, d, e = input().replace("vs. ", "").split() if b not in a.keys(): a[b] = 0 if e not in a.keys(): a[e] = 0 c = int(c) d = int(d) if c > d: a[b] += 3000 + c - d a[e] += d - c elif c < d: a[b] += c - d a[e] += 3000 + d - c else: a[b] += 1000 a[e] += 1000 f = sorted(a.items(), key=lambda x: x[1], reverse=True) print(f[0][0], f[1][0])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
T = int(input()) for _ in range(T): D = {} for i in range(12): a, b, e, d, c = map(str, input().split()) if a in D: if int(b) > int(d): D[a][0] += 3 elif int(b) == int(d): D[a][0] += 1 D[a][1] += int(b) - int(d) elif int(b) > int(d): D[a] = [3, int(b) - int(d)] elif int(b) == int(d): D[a] = [1, int(b) - int(d)] else: D[a] = [0, int(b) - int(d)] if c in D: if int(d) > int(b): D[c][0] += 3 elif int(b) == int(d): D[c][0] += 1 D[c][1] += int(d) - int(b) elif int(b) < int(d): D[c] = [3, int(d) - int(b)] elif int(b) == int(d): D[c] = [1, int(b) - int(d)] else: D[c] = [0, int(d) - int(b)] M = [] for m in D: D[m].append(m) M.append(D[m]) M.sort(reverse=True) print(M[0][2], M[1][2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) while t > 0: tot = [] x = 12 groups = [] score = [(0) for i in range(4)] gd = [(0) for i in range(4)] while x > 0: a = list(map(str, input().split())) t1 = a[0] s1 = a[1] s1 = int(s1) s2 = a[3] s2 = int(s2) t2 = a[4] if t1 not in groups: groups.append(t1) if t2 not in groups: groups.append(t2) if s1 > s2: score[groups.index(t1)] += 3 elif s2 > s1: score[groups.index(t2)] += 3 else: score[groups.index(t1)] += 1 score[groups.index(t2)] += 1 gd[groups.index(t1)] += s1 - s2 gd[groups.index(t2)] += s2 - s1 x = x - 1 for i in range(4): tot.append([score[i], gd[i], groups[i]]) tot.sort() out = [] out.append(tot[-1][-1]) out.append(tot[-2][-1]) print(*out) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
T = int(input()) for _ in range(T): d = {} initial_score = 0 initial_goal = 0 for i in range(12): scoreline = str(input()) score = scoreline.split() if score[0] not in list(d.keys()): d[score[0]] = [initial_score, initial_goal] if score[4] not in list(d.keys()): d[score[4]] = [initial_score, initial_goal] if int(score[1]) > int(score[3]): d[score[0]][0] += 3 d[score[0]][1] = d[score[0]][1] + (int(score[1]) - int(score[3])) d[score[4]][1] = d[score[4]][1] + (int(score[3]) - int(score[1])) elif int(score[3]) > int(score[1]): d[score[4]][0] += 3 d[score[4]][1] = d[score[4]][1] + (int(score[3]) - int(score[1])) d[score[0]][1] = d[score[0]][1] + (int(score[1]) - int(score[3])) else: d[score[0]][0] += 1 d[score[4]][0] += 1 table = list(dict(sorted(d.items(), key=lambda item: item[1])).keys()) print(table[-1], table[-2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST VAR VAR IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): teams = {} arr = [[0, 0, ""] for _ in range(4)] z = 0 for i in range(12): team1, team1score, x, team2score, team2 = list(input().split()) team1score = int(team1score) team2score = int(team2score) if team1 not in teams: teams[team1] = z arr[teams[team1]][2] = team1 z += 1 if team2 not in teams: teams[team2] = z arr[teams[team2]][2] = team2 z += 1 if team1score > team2score: arr[teams[team1]][0] += 3 elif team2score > team1score: arr[teams[team2]][0] += 3 else: arr[teams[team2]][0] += 1 arr[teams[team1]][0] += 1 arr[teams[team1]][1] += team1score - team2score arr[teams[team2]][1] += team2score - team1score arr.sort(reverse=True) print(arr[0][2], arr[1][2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST NUMBER NUMBER STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
n = int(input()) for j in range(n): arr = [] s = [] count = 0 d = {} c = {} j = [] for i in range(12): arr = list(input().split()) s.append(arr) a = int(s[i][1]) b = int(s[i][3]) q = [] u = {} s[i][1] = a s[i][3] = b if s[i][0] not in d: d[s[i][0]] = 0 c[s[i][0]] = 0 if s[i][4] not in d: d[s[i][4]] = 0 c[s[i][4]] = 0 if s[i][1] > s[i][3]: d[s[i][0]] += 3 c[s[i][0]] += s[i][1] - s[i][3] c[s[i][4]] += s[i][3] - s[i][1] elif s[i][3] > s[i][1]: d[s[i][4]] += 3 c[s[i][4]] += s[i][3] - s[i][1] c[s[i][0]] += s[i][1] - s[i][3] else: d[s[i][0]] += 1 d[s[i][4]] += 1 u = list(d.keys()) final = [] for i in range(4): final.append([d[u[i]], c[u[i]], u[i]]) final.sort(reverse=True) print(*[final[0][2], final[1][2]])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
t = int(input()) while t: ds = {} for i in range(12): ls = input().split(" ") if ls[0] not in ds: ds[ls[0]] = [int(ls[1]), int(ls[3]), 0] else: ds[ls[0]][0] += int(ls[1]) ds[ls[0]][1] += int(ls[3]) if ls[4] not in ds: ds[ls[4]] = [int(ls[3]), int(ls[1]), 0] else: ds[ls[4]][0] += int(ls[3]) ds[ls[4]][1] += int(ls[1]) if int(ls[1]) > int(ls[3]): ds[ls[0]][2] += 3 elif int(ls[1]) < int(ls[3]): ds[ls[4]][2] += 3 else: ds[ls[0]][2] += 1 ds[ls[4]][2] += 1 mVal = max(ds.values(), key=lambda x: x[2]) key = 0 for i in ds.keys(): if ds[i][2] == mVal[2] and mVal[0] - mVal[1] < ds[i][0] - ds[i][1]: key = i mVal = ds[i] elif ds[i] == mVal: key = i one = key ds.pop(key) val = max(ds.values(), key=lambda x: x[2]) for i in ds.keys(): if ds[i][2] == val[2] and val[0] - val[1] < ds[i][0] - ds[i][1]: key = i val = ds[i] elif ds[i] == val: key = i two = key print(one, two) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
for _ in range(int(input())): d = {} for i in range(12): a, b = map(str, input().split("vs. ")) a = a.split() b = b.split() if a[0] not in d: d[a[0]] = [0, 0] if b[1] not in d: d[b[1]] = [0, 0] diff_a = int(a[1]) - int(b[0]) d[a[0]][1] += diff_a diff_b = int(b[0]) - int(a[1]) d[b[1]][1] += diff_b if diff_a > diff_b: d[a[0]][0] += 3 elif diff_b > diff_a: d[b[1]][0] += 3 else: d[a[0]][0] += 1 d[b[1]][0] += 1 d = sorted(d, key=d.get) print(d[3], d[2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR IF VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
T = int(input()) for _ in range(T): fixtures = [] team_names = [] for j in range(12): fixture = input().split() fixtures.append(fixture) team_names.append(fixture[0]) fixt_dict = dict([(name, 0) for name in set(team_names)]) for team in fixt_dict.keys(): total_diff = 0 total_points = 0 fixt_dict[team] = dict([("points", total_points), ("goal_diff", total_diff)]) for fix in fixtures: home_goal = int(fix[1]) away_goal = int(fix[3]) goal_diff = 0 if team == fix[0]: goal_diff = home_goal - away_goal elif team == fix[4]: goal_diff = away_goal - home_goal if team == fix[0] or team == fix[4]: point_alloc = 0 if goal_diff > 0: point_alloc = 3 elif goal_diff == 0: point_alloc = 1 total_points += point_alloc total_diff += goal_diff fixt_dict[team]["goal_diff"] = total_diff fixt_dict[team]["points"] = total_points sorted_fict = dict( sorted( fixt_dict.items(), key=lambda tup: (tup[1]["points"], tup[1]["goal_diff"]), reverse=True, ) ) table = [k for k in sorted_fict.keys()] print(" ".join(table[:2]))
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 FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST STRING VAR STRING VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR STRING VAR ASSIGN VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. The UEFA Champions League is the most prestigious annual sports competition in the world. In the group stage of this competition, European football clubs are divided into 8 groups; there are four teams in each group. The teams in each group are ranked based on the matches they play against each other, according to the following rules: Based on the results of matches, teams are awarded *points*. Each football match is played between a *home team* and an *away team*. If one of the teams scores more goals than the other, this team gains $3$ points and the other team gains $0$ points. In case of a tie (if both teams score the same number of goals), each of those teams gains $1$ point. The *goal difference* of a team is the number of goals it scored minus the number of goals it received, regardless if it scored/received them as the home team or as the away team. Between any two teams, the team with more points is ranked higher. If they have the same number of points (in case of a tie), the team with higher goal difference is ranked higher. Each team plays two matches against every other team in its group ― one match as the home team and one match as the away team. You are given the number of goals scored by each team for all twelve matches in one group. Determine the leaders of this group ― the first and second top-ranked team. It is guaranteed that there are no ties for either of these places (for the given results of the matches). ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. For each test case, $12$ lines follow. Each of these lines describes the result of one match in the format HomeTeamName HomeTeamGoals vs. AwayTeamGoals AwayTeamName, where HomeTeamName and AwayTeamName are strings and HomeTeamGoals and AwayTeamGoals are integers denoting the number of goals scored by the respective teams in this match. ------ Output ------ For each scenario, print a single line containing two space-separated strings ― the name of the top-ranked team and the name of the second top-ranked team. ------ Constraints ------ $1 ≤ T ≤ 50$ the length of the name of each team does not exceed $10$ the name of each team contains only lowercase English letters $0 ≤$ number of goals scored by each team $≤ 100$ ----- Sample Input 1 ------ 2 manutd 8 vs. 2 arsenal lyon 1 vs. 2 manutd fcbarca 0 vs. 0 lyon fcbarca 5 vs. 1 arsenal manutd 3 vs. 1 fcbarca arsenal 6 vs. 0 lyon arsenal 0 vs. 0 manutd manutd 4 vs. 2 lyon arsenal 2 vs. 2 fcbarca lyon 0 vs. 3 fcbarca lyon 1 vs. 0 arsenal fcbarca 0 vs. 1 manutd a 3 vs. 0 b a 0 vs. 0 c a 0 vs. 0 d b 0 vs. 0 a b 4 vs. 0 c b 0 vs. 0 d c 0 vs. 0 a c 0 vs. 0 b c 1 vs. 0 d d 3 vs. 0 a d 0 vs. 0 b d 0 vs. 0 c ----- Sample Output 1 ------ manutd fcbarca d b ----- explanation 1 ------ Example case 1: The total number of points and goal difference for each team is as follows: - manutd: $16$ points, goal difference $12$ - fcbarca: $8$ points, goal difference $4$ - manutd: $5$ points, goal difference $-5$ - lyon: $4$ points, goal difference $-11$ Example case 2: The total number of points and goal difference for each team is as follows: - d: $7$ points, goal difference $2$ - b: $7$ points, goal difference $1$ - a: $7$ points, goal difference $0$ - c: $7$ points, goal difference $-3$ Note that in this test case, all teams have the same number of points, but teams with higher goal difference are ranked higher.
tcase = int(input()) while tcase > 0: pointdict = {} gddict = {} for q in range(12): match = input().split(" vs. ") score = [] team = [] for i in match: for j in i.split(): if j.isdigit(): score.append(int(j)) elif j.isalpha(): team.append(j) for i in range(len(team)): if team[i] not in pointdict: pointdict[team[i]] = 0 if team[i] not in gddict: gddict[team[i]] = 0 for i in score: i = int(i) if score[0] > score[1]: pointdict[team[0]] += 3 gddict[team[0]] += score[0] - score[1] gddict[team[1]] += score[1] - score[0] elif score[1] > score[0]: pointdict[team[1]] += 3 gddict[team[0]] += score[0] - score[1] gddict[team[1]] += score[1] - score[0] else: pointdict[team[1]] += 1 pointdict[team[0]] += 1 gddict[team[0]] += score[0] - score[1] gddict[team[1]] += score[1] - score[0] secpoint = 0 scores = [] gds = [] teams = [] for j in pointdict.values(): scores.append(j) for k in gddict.values(): gds.append(k) for l in pointdict.keys(): teams.append(l) maxpoint = max(scores) if scores.count(maxpoint) > 1: secpoint = maxpoint else: for i in range(len(scores)): if scores[i] > secpoint and scores[i] < maxpoint: secpoint = scores[i] finalmax = "" finalsecmax = "" if scores.count(maxpoint) == 1: finalmax += teams[scores.index(maxpoint)] else: s = [] for i in teams: if scores[teams.index(i)] == maxpoint: s.append(i) g = [] for i in s: g.append(gds[teams.index(i)]) finalmax += teams[gds.index(max(g))] if scores.count(secpoint) == 1: finalsecmax += teams[scores.index(secpoint)] else: s = [] for i in teams: if scores[teams.index(i)] == secpoint: s.append(i) g = [] for i in s: if ( scores[teams.index(i)] == secpoint and gds[teams.index(i)] != gds[teams.index(finalmax)] ): g.append(gds[teams.index(i)]) finalsecmax += teams[gds.index(max(g))] print(finalmax, finalsecmax) tcase -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
def check_mean_median(arr, n, x): cost_mean = n * x - sum(arr) if cost_mean < 0: return -1 cost_median = 0 for i in range((n - 1) // 2, n): cost_median += max(0, x - arr[i]) if cost_median > cost_mean: return -1 else: return cost_mean def solve(arr, n): arr.sort() low, high, ans = arr[(n - 1) // 2], 10**9 + 10, -1 while low <= high: mid = low + (high - low) // 2 min_oper = check_mean_median(arr, n, mid) if min_oper != -1: ans = min_oper high = mid - 1 else: low = mid + 1 print(ans) t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) solve(arr, n)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
def snek(a, n, x): c = n * x - sum(a) if c < 0: return -1 c2 = 0 for i in range((n - 1) // 2, n): c2 += max(0, x - a[i]) if c2 > c: return -1 else: return c t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) a.sort() l, h, ans = a[(n - 1) // 2], 10**9 + 10, -1 while l <= h: m1 = l + (h - l) // 2 m2 = snek(a, n, m1) if m2 != -1: ans = m2 h = m1 - 1 else: l = m1 + 1 print(ans)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
def check(arr, mean, n): sum = 0 for i in range(len(arr)): sum += arr[i] allowed_operations = n * mean - sum if allowed_operations < 0: return -1 required_operations = 0 for i in range((n - 1) // 2, n): required_operations += max(0, mean - arr[i]) if required_operations > allowed_operations: return -1 else: return allowed_operations for i in range(int(input())): N = int(input()) arr = [int(x) for x in input().split()] arr = sorted(arr) l = arr[(len(arr) - 1) // 2] r = arr[len(arr) - 1] ans = -1 n = len(arr) while l <= r: mid = (l + r) // 2 minOp = check(arr, mid, n) if minOp != -1: ans = minOp r = mid - 1 else: l = mid + 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) A.sort() s = sum(A) low = A[(n - 1) // 2] high = 10**9 ans = 10**9 while low <= high: k = (low + high) // 2 mean = k * n - s median = 0 for i in range((n - 1) // 2, n): median += max(0, k - A[i]) if mean >= median: ans = mean high = k - 1 else: low = k + 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
def cal(arr, n, med): ind = n // 2 - 1 if n % 2 == 0 else (n + 1) // 2 - 1 c = 0 for i in range(ind, n): if i == ind: c += med - arr[ind] arr[ind] = med elif arr[i - 1] > arr[i]: c += arr[i - 1] - arr[i] arr[i] = arr[i - 1] tot = sum(arr) if tot > med * n: return -1 else: return c + (med * n - tot) for _ in range(int(input())): n = int(input()) arr = sorted(list(map(int, input().split()))) tot = sum(arr) median = arr[n // 2 - 1] if n % 2 == 0 else arr[(n + 1) // 2 - 1] if tot == median * n: print(0) elif tot < median * n: print(median * n - tot) else: l = median + 1 h = 10**9 + 1 fc = 10**18 while l <= h: mid = (l + h) // 2 cost = cal(arr[:], n, mid) if cost == -1: l = mid + 1 else: fc = min(fc, cost) h = mid - 1 print(fc)
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
from sys import stdin input = stdin.readline def check(x): ans = 0 for i in range(middle, n): ans += max(0, x - a[i]) if n * x < s + ans: return -1 return n * x - (s + ans) + ans def answer(): s = sum(a) l, h = a[middle], a[-1] while l <= h: mid = (l + h) // 2 value = check(mid) if value != -1: ans = value h = mid - 1 else: l = mid + 1 return ans for T in range(int(input())): n = int(input()) a = sorted(list(map(int, input().split()))) s = sum(a) middle = n // 2 if n & 1 == 0: middle -= 1 print(answer())
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] a.sort() mod_in = (n - 1) // 2 l = a[mod_in] - 1 r = 10**9 while r - l > 1: cur = (l + r) // 2 meanop = cur * n - sum(a) medianop = 0 for i in range(mod_in, n): medianop += max(0, cur - a[i]) if meanop >= medianop: r = cur else: l = cur print(r * n - sum(a))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
for _ in range(int(input())): n = int(input()) arr = [int(x) for x in input().split(" ")] arr.sort() s = sum(arr) mean = s / n med = arr[(n - 1) // 2] if med == mean: print(0) continue def check(k): meanop = k * n - s medop = 0 for i in range((n - 1) // 2, n): if arr[i] < k: medop += k - arr[i] else: break if meanop >= medop: return meanop return -1 l = med h = arr[-1] ans = 0 while l <= h: mid = l + (h - l) // 2 a = check(mid) if a == -1: l = mid + 1 else: ans = a h = mid - 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
def possible(rmd): rs = n * rmd cs = s for j in range(md, n): cs += max(rmd - a[j], 0) if rs < cs: return False, -1 return True, rs - s for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = sum(a) a.sort() ans = float("inf") if n & 1: md = n // 2 else: md = n // 2 - 1 md2 = s // n mod = s % n if mod != 0: md2 += 1 l = max(a[md], md2) r = a[-1] p = 0 while l <= r: mid = l + (r - l) // 2 check = possible(mid) if check[0]: if ans > check[1]: ans = check[1] p = mid r = mid - 1 else: l = mid + 1 print(ans)
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER NUMBER RETURN NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
import sys input = sys.stdin.readline def feasible(arr, tar, total): N = len(arr) meanop = N * tar - total medianop = 0 for i in range((N - 1) // 2, N): medianop += max(0, tar - arr[i]) if meanop >= medianop: return meanop return -1 t = int(input()) for case in range(t): n = int(input()) A = list(map(int, input().split())) A.sort() l = A[(n - 1) // 2] r = 10**9 total = sum(A) while l <= r: mid = (l + r) // 2 res = feasible(A, mid, total) if res != -1: r = mid - 1 ans = res else: l = mid + 1 print(ans)
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
import sys int1 = lambda x: int(x) - 1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 18446744073709551615 md = 10**9 + 7 def solve(): def binary_search(l, r, ok, minimize): if minimize: l -= 1 else: r += 1 while l + 1 < r: m = (l + r) // 2 if ok(m) ^ minimize: l = m else: r = m if minimize: return r return l def ok(v): if v * n < s: return False t = v * n for i in range(mid, n): t -= max(v, aa[i]) return t >= pre n = II() aa = LI() mid = (n - 1) // 2 aa.sort() pre = sum(aa[:mid]) s = sum(aa) m = aa[mid] v = binary_search(m, 10**9 + 5, ok, True) ans = v * n - s print(ans) for _ in range(II()): solve()
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR STRING STRING VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF FUNC_DEF IF VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR RETURN VAR RETURN VAR FUNC_DEF IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
def findMedian(A): return A[(len(A) - 1) // 2] def isX(A, X): summ = 0 for i in range(len(A)): if i < (len(A) - 1) // 2: summ += A[i] else: summ += max(X, A[i]) return summ <= len(A) * X for t in range(int(input())): N = int(input()) A = list(map(int, input().split())) A.sort() sumA = sum(A) originalMedian = findMedian(A) if originalMedian * N >= sumA: print(originalMedian * N - sumA) else: l = int(originalMedian) r = max(A) while r - l > 1: mid = (l + r) // 2 if isX(A, mid): r = int(mid) else: l = int(mid) print(r * N - sumA)
FUNC_DEF RETURN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = list(map(int, input().split())) q = int(input()) qu = list() an = [-1] * n m = 0 for i in range(q): qu.append(tuple(map(int, input().split()))) for i in range(q): k = qu[q - i - 1] if k[0] == 2: m = max(m, k[1]) elif an[k[1] - 1] == -1: an[k[1] - 1] = max(m, k[2]) for i in range(n): if an[i] == -1: an[i] = max(m, a[i]) print(*an)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.buffer.readline n = int(input()) a = list(map(int, input().split())) answers = [-1] * n last_all_update = [-1, 0] updates = [[1, i + 1, a[i]] for i in range(n)] q = int(input()) for i in range(1, q + 1): updates.append(list(map(int, input().split()))) curr_mx = 0 for i in range(len(updates) - 1, -1, -1): a = updates[i] if a[0] == 1: if answers[a[1] - 1] == -1: answers[a[1] - 1] = max(curr_mx, a[2]) else: curr_mx = max(curr_mx, a[1]) print(*answers)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin, stdout class Stree: def __init__(self, f, n, default, init_data): self.ln = 2 ** (n - 1).bit_length() self.data = [default] * (self.ln * 2) self.f = f for i, d in init_data: self.data[self.ln + i] = d for j in range(self.ln - 1, -1, -1): self.data[j] = f(self.data[j * 2], self.data[j * 2 + 1]) def get(self, i, j): def _get(l, r, p): if i <= l and j >= r: return self.data[p] else: m = (l + r) // 2 if j <= m: return _get(l, m, p * 2) elif i >= m: return _get(m, r, p * 2 + 1) else: return self.f(_get(l, m, p * 2), _get(m, r, p * 2 + 1)) return _get(0, self.ln, 1) def input(): return next(stdin) n = int(input()) aa = list(map(int, input().split())) q = int(input()) fixTime = [0] * n payouts = [] for i in range(q): e = list(map(int, input().split())) if e[0] == 1: j = e[1] - 1 aa[j] = e[2] fixTime[j] = i else: payouts.append((i, e[1])) stree = Stree(max, q, 0, payouts) for i in range(n): aa[i] = max(aa[i], stree.get(fixTime[i], q)) print(*aa)
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR NUMBER VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
citizensCount, citizens, requestsCount = ( int(input()), [*map(int, input().split())], int(input()), ) operations = [] for _ in range(requestsCount): type, *cmd = map(int, input().split()) operations.append((type, cmd)) wagesChanges = [(-1) for _ in range(citizensCount)] secondTypeMax = -1 for type, op in reversed(operations): if type == 2: secondTypeMax = max(secondTypeMax, op[0]) else: citizenIndex, newIncome = op citizenIndex -= 1 if wagesChanges[citizenIndex] == -1: wagesChanges[citizenIndex] = max(newIncome, secondTypeMax) print( " ".join( str(b if b != -1 else max(secondTypeMax, a)) for a, b in zip(citizens, wagesChanges) ) )
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline def construct(array, cur_pos, tree, start, end): if start == end: tree[cur_pos] = array[start] else: mid = (start + end) // 2 tree[cur_pos] = max( construct(array, 2 * cur_pos + 1, tree, start, mid), construct(array, 2 * cur_pos + 2, tree, mid + 1, end), ) return tree[cur_pos] def query(start, end, l, r, index, tree): if l <= start and r >= end: return tree[index] if end < l or start > r: return -1 mid = (start + end) // 2 return max( query(start, mid, l, r, 2 * index + 1, tree), query(mid + 1, end, l, r, 2 * index + 2, tree), ) n = int(input()) l = list(map(int, input().split())) q = int(input()) last_query = [-1] * n queries = [-1] * q for i in range(q): l1 = list(map(int, input().split())) if l1[0] == 1: index = l1[1] - 1 value = l1[2] l[index] = value last_query[index] = i else: queries[i] = l1[1] tree = [0] * (5 * q) array = queries construct(array, 0, tree, 0, q - 1) for i in range(n): temp = last_query[i] if temp + 1 < q: q1 = query(0, q - 1, temp + 1, q - 1, 0, tree) l[i] = max(q1, l[i]) print(*l, sep=" ")
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys n = int(input()) a = [int(i) for i in input().split(" ")] lasts = [0] * n q = int(input()) mins = [] trs = [] for i in range(0, q): tr = [int(i) for i in sys.stdin.readline().rstrip().split(" ")] if tr[0] == 1: a[tr[1] - 1] = tr[2] lasts[tr[1] - 1] = i trs.append(tr) ct = 0 for i in range(len(trs) - 1, -1, -1): if trs[i][0] == 2: if ct == 0: mins.append(trs[i][1]) else: mins.append(max(mins[-1], trs[i][1])) elif ct == 0: mins.append(0) else: mins.append(mins[-1]) ct += 1 mins = mins[::-1] carr = [] for i in range(0, len(a)): carr.append(max(a[i], mins[lasts[i]])) print(" ".join([str(i) for i in carr]))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin input = stdin.readline n = int(input()) money = list(map(int, input().split(" "))) m = int(input()) tmp = 0 up = [(0) for i in range(m)] last = [(0) for i in range(n)] for i in range(m): req = list(map(int, input().split(" "))) if req[0] == 2: up[i] = req[1] else: money[req[1] - 1] = req[2] last[req[1] - 1] = i for i in range(m - 2, -1, -1): up[i] = max(up[i], up[i + 1]) for i in range(n): money[i] = max(money[i], up[last[i]]) for i in range(n): print(money[i], end=" ")
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin input = stdin.readline n = int(input()) a = [int(i) for i in input().split()] q = int(input()) payoff = [0] * q a_receipt = [0] * n for _ in range(q): pay = [int(i) for i in input().split()] if pay[0] == 1: a[pay[1] - 1] = pay[2] a_receipt[pay[1] - 1] = _ else: payoff[_] = pay[1] max_payoff = 0 for i in range(q): max_payoff = max([max_payoff, payoff[q - i - 1]]) payoff[q - i - 1] = max_payoff for i in range(n): print(max([a[i], payoff[a_receipt[i]]]), end=" ")
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin, stdout for _ in range(1): n = int(stdin.readline()) last = [0] * n a = list(map(int, stdin.readline().split())) update = [] qq = int(stdin.readline()) for q in range(qq): pair = list(map(int, stdin.readline().split())) if pair[0] == 2: update += [pair[1]] else: last[pair[1] - 1] = q a[pair[1] - 1] = pair[2] update += [0] for i in range(qq - 2, -1, -1): update[i] = max(update[i + 1], update[i]) for i in range(n): a[i] = max(a[i], update[last[i]]) print(*a)
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER VAR LIST VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
[n] = [int(w) for w in input().split()] a = [int(w) for w in input().split()] [q] = [int(w) for w in input().split()] o = [(x, 0) for x in a] s = [(0) for t in range(q + 1)] for t in range(1, q + 1): c, *xs = [int(w) for w in input().split()] if c == 1: p, x = xs o[p - 1] = x, t else: [x] = xs s[t] = x m = 0 for t in range(q, -1, -1): if s[t] > m: m = s[t] else: s[t] = m print(*[max(x, s[t]) for x, t in o])
ASSIGN LIST VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN LIST VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin as cin from sys import stdout as cout get = cin.readline end = cout.flush def put(x): cout.write(str(x)) input = cout.readline n = int(get()) ar = list(map(int, get().split())) q = int(get()) p = [] for i in range(q): x = tuple(map(int, get().split())) p.append(x) mod = [0] * n cur_max = -1 p = p[::-1] for i in p: if i[0] == 1: if mod[i[1] - 1] == 0: ar[i[1] - 1] = max(cur_max, i[2]) mod[i[1] - 1] = 1 else: cur_max = max(cur_max, i[1]) for i in range(n): if mod[i] == 0: ar[i] = max(ar[i], cur_max) put(" ".join(str(i) for i in ar)) end()
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys n = int(sys.stdin.readline()) data = [int(i) for i in sys.stdin.readline().split()] q = int(sys.stdin.readline()) welfare = [0] * (q + 1) tw = [] changes = [(0, 0)] + [(0, a) for a in data] for i in range(1, q + 1): qu = [int(i) for i in sys.stdin.readline().split()] if qu[0] == 1: changes[qu[1]] = i, qu[2] else: tw.append((i, qu[1])) ind = len(tw) - 1 maxw = -1 time = q + 1 while ind >= 0: welf = tw[ind] for i in range(welf[0], time): welfare[i] = maxw time = welf[0] if welf[1] > maxw: maxw = welf[1] ind -= 1 for i in range(time): welfare[i] = maxw ans = [] for i in range(1, n + 1): lastch = changes[i] if welfare[lastch[0]] > lastch[1]: ans.append(str(welfare[lastch[0]])) else: ans.append(str(lastch[1])) sys.stdout.write(" ".join(ans) + "\n")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) array = list(map(int, input().split())) q = int(input()) d = {i: (0) for i in range(n)} stack = [] for i in range(q): req = list(map(int, input().split())) if req[0] == 2: stack.append((req[1], i)) else: p = req[1] - 1 d[p] = i array[p] = req[2] ans_i = [-1] * q j = len(stack) - 1 max_of_stack = -1 for i in range(q - 1, -1, -1): if j > -1 and stack[j][1] >= i: max_of_stack = max(max_of_stack, stack[j][0]) j -= 1 ans_i[i] = max_of_stack for p in range(n): if array[p] < ans_i[d[p]]: array[p] = ans_i[d[p]] print(*array)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline n = int(input()) for _ in range(1): arr = list(map(int, input().split())) q = int(input()) ql = [] for iq in range(q): ql += [list(map(int, input().split()))] useful = [] maxi = 0 for i in range(q - 1, -1, -1): if ql[i][0] == 2: if ql[i][1] > maxi: useful += [ql[i]] maxi = ql[i][1] else: useful += [ql[i]] useful.reverse() flag = 0 d = dict() maxi = 0 for i in range(len(useful)): if useful[i][0] == 2: maxi = useful[i][1] if flag == 0: for j in range(len(arr)): if arr[j] < useful[i][1]: arr[j] = useful[i][1] flag = 1 else: l = [] for j in d: if arr[j] <= useful[i][1]: arr[j] = useful[i][1] l += [j] for j in l: del d[j] else: useful[i][1] -= 1 if flag == 0: arr[useful[i][1]] = useful[i][2] else: arr[useful[i][1]] = useful[i][2] if useful[i][2] < maxi: d[useful[i][1]] = 1 print(*arr)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR LIST VAR FOR VAR VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline n = int(input()) l = list(map(int, input().split())) lUpd = [0] * n q = int(input()) payoff = [-1] * q for query in range(q): qnext = list(map(int, input().split())) if qnext[0] == 1: p = qnext[1] - 1 x = qnext[2] l[p] = x lUpd[p] = query else: x = qnext[1] payoff[query] = x maxPayoff = [-1] * q best = -1 for i in range(q - 1, -1, -1): best = max(best, payoff[i]) maxPayoff[i] = best out = [max(l[p], maxPayoff[lUpd[p]]) for p in range(n)] print(" ".join(map(str, out)))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin input = stdin.readline n = int(input()) a = list(map(int, input().split())) input() t = [True] * n x = 0 for inn in stdin.readlines()[::-1]: l = list(map(int, inn.split())) i = l[1] - 1 if len(l) == 3 and t[i]: a[i] = max(l[2], x) t[i] = False elif len(l) == 2: x = max(x, l[1]) for i in range(n): if t[i]: a[i] = max(a[i], x) print(*a)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = [int(X) for X in input().split()] vis = [0] * n c = 0 tt = [] for j in range(int(input())): s = input().split() if s[0] == "1": p, x = map(int, s[1:]) a[p - 1] = x vis[p - 1] = c else: tt.append(int(s[1])) c += 1 for j in range(len(tt) - 2, -1, -1): tt[j] = max(tt[j], tt[j + 1]) tt = tt + [0] print(*[max(a[i], tt[vis[i]]) for i in range(n)])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin, stdout N = int(input()) arr = [int(x) for x in stdin.readline().split()] Q = int(input()) logg = [0] * Q t = [0] * Q account = [0] * Q m = [0] * Q valid = [1] * Q for i in range(Q): a = [int(x) for x in stdin.readline().split()] if a[0] == 1: account[i] = a[1] t[i] = 1 logg[i] = a[2] else: logg[i] = a[1] t[i] = 2 maxi = -1 for i in range(Q - 1, -1, -1): if t[i] == 2: maxi = max(maxi, logg[i]) m[i] = maxi for i in range(Q): if logg[i] < m[i]: valid[i] = 0 for i in range(N): if arr[i] < maxi: arr[i] = maxi for i in range(Q): if valid[i] == 1 and t[i] == 1: arr[account[i] - 1] = logg[i] elif valid[i] == 0 and t[i] == 1: arr[account[i] - 1] = m[i] print(*arr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
def main(): n = int(input()) money = list(map(int, input().split())) last_change = [-1] * n dp = [] q = int(input()) second = [] for i in range(q): query = list(map(int, input().split())) if query[0] == 1: dp.append(-1) p, x = query[1], query[2] money[p - 1] = x last_change[p - 1] = i else: second.append(query[1]) dp.append(query[1]) for i in range(len(dp) - 2, -1, -1): dp[i] = max(dp[i + 1], dp[i]) for i in range(n): if last_change[i] == -1: money[i] = max(dp[0], money[i]) else: change = last_change[i] if change + 1 < len(dp): max_val = dp[change + 1] else: max_val = -1 money[i] = max(max_val, money[i]) for i in money: print(i, end=" ") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys read = sys.stdin.readline n = int(read()) balance = list(map(int, read().split(" "))) n_operations = int(read()) minis = [] next_mini = 0 changed_before = [0] * (len(balance) + 1) for n_op in range(n_operations): operation = list(map(int, read().split(" "))) if operation[0] == 1: x = operation[1] - 1 balance[x] = operation[2] changed_before[x] = next_mini elif operation[0] == 2: minis.append(operation[1]) next_mini += 1 if len(minis) > 0: max_mini = minis[-1] for m in range(1, len(minis) + 1): max_mini = max(max_mini, minis[m * -1]) minis[m * -1] = max_mini for x in range(len(balance)): cb = changed_before[x] if cb < next_mini: balance[x] = max(minis[cb], balance[x]) balance[x] = str(balance[x]) else: for x in range(len(balance)): balance[x] = str(balance[x]) print(" ".join(balance))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
R = lambda: map(int, input().split()) n = int(input()) a = *zip([1] * n, range(1, n + 1), R()), *([*R()] for _ in [0] * int(input())) r = [-1] * n m = 0 for t, p, *x in a[::-1]: if t > 1: m = max(m, p) elif r[p - 1] < 0: r[p - 1] = max(x[0], m) print(*r)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) arr = list(map(int, input().rstrip().split())) q = int(input()) events = [] for i in range(q): a = list(map(int, input().rstrip().split())) events.append(a) changes = {} for i in range(q): if events[i][0] == 1: if events[i][1] not in changes.keys(): changes.update({events[i][1]: i}) else: changes[events[i][1]] = i max_payoff = {} for i in changes.keys(): max_payoff.update({changes[i]: 0}) max_pay = 0 for i in range(q - 1, -1, -1): if events[i][0] == 2: if max_pay < events[i][1]: max_pay = events[i][1] if i in max_payoff.keys(): max_payoff[i] = max_pay for i in range(1, len(arr) + 1): if i in changes.keys(): arr[i - 1] = max(max_payoff[changes[i]], events[changes[i]][2]) elif arr[i - 1] < max_pay: arr[i - 1] = max_pay for i in arr: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER IF VAR VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR DICT VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR DICT VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline class SegmentTree: def __init__(self, n): self.size = 1 while self.size < n: self.size *= 2 self.node = [0] * (2 * self.size - 1) def update(self, i, val): i += self.size - 1 self.node[i] = val while i > 0: i = (i - 1) // 2 self.node[i] = max(self.node[2 * i + 1], self.node[2 * i + 2]) def get_max(self, begin, end): begin += self.size - 1 end += self.size - 1 s = 0 while begin < end: if end - 1 & 1: end -= 1 s = max(s, self.node[end]) if begin - 1 & 1: s = max(s, self.node[begin]) begin += 1 begin = (begin - 1) // 2 end = (end - 1) // 2 return s n = int(input()) a = list(map(int, input().split())) q = int(input()) info = [list(map(int, input().split())) for i in range(q)] st = SegmentTree(q) li = [0] * n for i in range(q): if info[i][0] == 1: ind = info[i][1] - 1 a[ind] = info[i][2] li[ind] = i else: st.update(i, info[i][1]) ans = [0] * n for i in range(n): tmp = max(st.get_max(li[i], q), a[i]) ans[i] = tmp print(" ".join(map(str, ans)))
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
R = lambda: map(int, input().split()) n = int(input()) a = list(R()) q = int(input()) p = [] ax = [-1] * n for _ in range(q): p.append(list(R())) temp = 0 for i in range(q - 1, -1, -1): if p[i][0] == 2: temp = max(temp, p[i][1]) elif ax[p[i][1] - 1] == -1: ax[p[i][1] - 1] = max(temp, p[i][2]) for i in range(0, n): if ax[i] == -1: print(max(temp, a[i]), end=" ") else: print(ax[i], end=" ")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
N = int(input()) List = [int(x) for x in input().split()] query = [] q = int(input()) for i in range(q): x = [int(x) for x in input().split()] query.append(x) second = [-1] * q if query[q - 1][0] == 2: second[q - 1] = query[q - 1][1] for i in range(q - 2, -1, -1): if query[i][0] == 2: second[i] = max(second[i + 1], query[i][1]) else: second[i] = second[i + 1] first = [-1] * N for i in range(q): if query[i][0] == 1: first[query[i][1] - 1] = i for i in range(N): if first[i] != -1: List[i] = query[first[i]][2] List[i] = max(List[i], second[first[i]]) elif second[0] != -1: List[i] = max(List[i], second[0]) print(*List)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) lis = list(map(int, input().split())) lis = [[0, i] for i in lis] k = int(input()) li = [] m = 0 for i in range(k): li.append(list(map(int, input().split()))) for i in range(k): if len(li[k - i - 1]) == 2: m = max(li[k - i - 1][1], m) elif lis[li[k - i - 1][1] - 1][0] == 0: lis[li[k - i - 1][1] - 1][0] = 1 lis[li[k - i - 1][1] - 1][1] = max(m, li[k - i - 1][2]) for i in range(n): if lis[i][0] == 0: lis[i][1] = max(m, lis[i][1]) for i in range(n): print(lis[i][1], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) l = [int(i) for i in input().split()] q = int(input()) t = [-1] * n upd = [0] * q for i in range(q): k = [int(x) for x in input().split()] if k[0] == 1: l[k[1] - 1] = k[2] t[k[1] - 1] = i else: upd[i] = k[1] for i in range(q - 2, -1, -1): upd[i] = max(upd[i], upd[i + 1]) for i in range(n): if i < n and t[i] + 1 < q: l[i] = max(l[i], upd[t[i] + 1]) print(*l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().rstrip().split()] marked = [False] * n q = int(stdin.readline()) op = [] for i in range(q): op.append([int(i) for i in stdin.readline().rstrip().split()]) op.reverse() max_so_far = 0 for o in op: if o[0] == 1: i = o[1] - 1 v = o[2] if not marked[i]: marked[i] = True a[i] = max(max_so_far, v) else: v = o[1] max_so_far = max(max_so_far, v) ans = "" for i in range(n): if not marked[i]: marked[i] = True a[i] = max(a[i], max_so_far) stdout.write(str(a[i])) if i == n - 1: stdout.write("\n") else: stdout.write(" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) qq = int(input()) queries = [list(map(int, input().split())) for _ in range(qq)] queries.reverse() ans = [-1] * n payoff = 0 for q in queries: if q[0] == 1: if ans[q[1] - 1] == -1: ans[q[1] - 1] = max(payoff, q[2]) else: payoff = max(payoff, q[1]) for i in range(n): if ans[i] == -1: ans[i] = max(payoff, a[i]) print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys in_file = sys.stdin n = int(in_file.readline().strip()) A = list(map(int, in_file.readline().strip().split())) q = int(in_file.readline().strip()) flood = [] last = [(0) for a in A] for i in range(q): t = list(map(int, in_file.readline().strip().split())) if t[0] == 1: A[t[1] - 1] = t[2] last[t[1] - 1] = i flood.append(0) else: flood.append(t[1]) flood_max = [flood[-1]] for i in range(len(flood) - 1): flood_max.append(max(flood_max[-1], flood[len(flood) - i - 2])) flood_max.reverse() for i in range(len(A)): A[i] = max(A[i], flood_max[last[i]]) sys.stdout.write(" ".join(map(str, A))) sys.stdout.flush()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = list(map(int, input().split())) m = int(input()) o = [list(map(int, input().split())) for _ in range(m)] b = [0] * m x = 0 for i in range(m - 1, -1, -1): if o[i][0] == 2: x = max(x, o[i][1]) b[i] = x for i in range(n): a[i] = max(a[i], b[0]) for i in range(m): if o[i][0] == 1: a[o[i][1] - 1] = max(o[i][2], b[i]) print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) balance = list(map(int, input().split())) q = int(input()) log = [list(map(int, input().split())) for i in range(q)] ind_of_last_operation = [None] * n max_pay = 0 ind_of_max_payment = None payments = [] payments_id = [] for i in range(q): if log[i][0] == 1: ind_of_last_operation[log[i][1] - 1] = i for i in range(q): if log[i][0] == 2: ind_of_last_payment = i last_payment = log[i][1] if log[i][1] > max_pay: max_pay = log[i][1] max_pay_for_moment = [0] * (q + 1) for j in range(q - 1, -1, -1): if log[j][0] == 2: max_pay_for_moment[j] = max(log[j][1], max_pay_for_moment[j + 1]) else: max_pay_for_moment[j] = max_pay_for_moment[j + 1] for i in range(n): if ind_of_last_operation[i] == None: if balance[i] < max_pay: balance[i] = max_pay elif ( max_pay_for_moment[ind_of_last_operation[i] + 1] > log[ind_of_last_operation[i]][2] ): balance[i] = max_pay_for_moment[ind_of_last_operation[i] + 1] else: balance[i] = log[ind_of_last_operation[i]][2] print(*balance)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline for nt in range(1): n = int(input()) l = list(map(int, input().split())) q = int(input()) last = {} maxx = [0] * q t2 = [] for i in range(q): temp = list(map(int, input().split())) if temp[0] == 1: last[temp[1]] = temp[2], i else: t2.append((temp[1], i)) if len(t2) > 0: j = len(t2) - 1 m = -1 for i in range(q - 1, -1, -1): if i > t2[j][1]: maxx[i] = m else: maxx[i] = max(t2[j][0], m) j -= 1 m = maxx[i] ans = [] for i in range(n): if i + 1 in last: ans.append(max(last[i + 1][0], maxx[last[i + 1][1]])) else: ans.append(max(maxx[0], l[i])) print(*ans)
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline n = int(input()) li = list(map(int, input().split())) check = [-1] * n maxx = 0 for i in [input().split() for i in range(int(input()))][::-1]: if i[0] == "2": maxx = max(maxx, int(i[1])) elif check[int(i[1]) - 1] == -1: check[int(i[1]) - 1] = max(int(i[2]), maxx) for i in range(n): if check[i] == -1: check[i] = max(maxx, li[i]) print(*check)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys in_file = sys.stdin n = int(in_file.readline().strip()) a = list(map(int, in_file.readline().strip().split())) q = int(in_file.readline().strip()) ls = [list(map(int, in_file.readline().strip().split())) for _ in range(q)] mxs = [-1] * q mxs[-1] = ls[-1][1] if ls[-1][0] == 2 else -1 for i in range(q - 2, -1, -1): mxs[i] = max(mxs[i + 1], ls[i][1] if ls[i][0] == 2 else -1) o = [max(mxs[0], x) for x in a] for i in range(q): if ls[i][0] != 1: continue p, x = ls[i][1:] o[p - 1] = max(x, mxs[i]) sys.stdout.write(" ".join(map(str, o))) sys.stdout.flush()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
iYdqL = int iYdqt = input iYdqI = list iYdqK = map iYdqp = range iYdqb = len iYdqc = reversed iYdqx = max iYdqr = print n = iYdqL(iYdqt()) a = iYdqI(iYdqK(iYdqL, iYdqt().split())) q = iYdqL(iYdqt()) s = [(0) for i in iYdqp(iYdqb(a))] f = [(0) for i in iYdqp(q)] for i in iYdqp(q): r = iYdqI(iYdqK(iYdqL, iYdqt().split())) if r[0] == 1: s[r[1] - 1] = i a[r[1] - 1] = r[2] else: f[i] = r[1] for i in iYdqc(iYdqp(0, q - 1)): f[i] = iYdqx(f[i], f[i + 1]) for i in iYdqp(n): a[i] = iYdqx(a[i], f[s[i]]) iYdqr(*a)
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.buffer.readline def solution(): n = int(input()) l = list(map(int, input().split())) m = -1 a = [-1] * n q = [] for _ in range(int(input())): t = list(map(int, input().split())) q.append(t) for t in q[::-1]: if t[0] == 1 and a[t[1] - 1] == -1: a[t[1] - 1] = max(t[2], m) if t[0] == 2: m = max(t[1], m) for i in range(n): if a[i] == -1: a[i] = max(l[i], m) print(*a) solution()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (n,) = I() l = I() (q,) = I() ar = [-1] * n tm = 0 qr = [] for i in range(q): qr.append(I()) for i in range(q - 1, -1, -1): r = qr[i] if r[0] == 1: if ar[r[1] - 1] == -1: ar[r[1] - 1] = max(r[2], tm) else: tm = max(tm, r[1]) for i in range(n): l[i] = max(tm, l[i]) if ar[i] == -1 else ar[i] print(l[i], end=" ")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = list(map(int, input().split())) q = int(input()) changes = [0] * q for i in range(q): changes[-i - 1] = tuple(map(int, input().split())) final = [-1] * n curr = 0 for guy in changes: if guy[0] == 1: if final[guy[1] - 1] == -1: final[guy[1] - 1] = max(guy[2], curr) else: curr = max(curr, guy[1]) for i in range(n): if final[i] == -1: final[i] = max(curr, a[i]) final = [str(guy) for guy in final] print(" ".join(final))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline prnt = sys.stdout.write n = int(input()) a = list(map(int, input().split())) q = int(input()) ls = [] last = [-1] * n for i in range(q): x = list(map(int, input().split())) ls.append(x) if x[0] == 1: last[x[1] - 1] = i mxsf = [-1] * (q + 1) for i in range(q - 1, -1, -1): if ls[i][0] == 2: mxsf[i] = ls[i][1] mxsf[i] = max(mxsf[i], mxsf[i + 1]) for i in range(n): if last[i] == -1: a[i] = max(a[i], mxsf[0]) else: a[i] = max(mxsf[last[i]], ls[last[i]][2]) print(" ".join([str(i) for i in a]))
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input().strip()) a = list(map(int, input().split())) q = int(input().strip()) queries = [] last_balance = [-1] * n last_balance_id = [-1] * n for i in range(q): query = list(map(int, input().split())) queries.append(query) if query[0] == 1: p = query[1] - 1 last_balance[p] = query[2] last_balance_id[p] = i max_pay = [0] * (q + 1) for i in range(q - 1, -1, -1): query = queries[i] if query[0] == 2: max_pay[i] = max(query[1], max_pay[i + 1]) else: max_pay[i] = max_pay[i + 1] for p in range(n): if last_balance_id[p] >= 0: id = last_balance_id[p] pay = max_pay[id] a[p] = max(pay, last_balance[p]) else: a[p] = max(a[p], max_pay[0]) print(" ".join([str(x) for x in a]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = list(map(int, input().split())) q = int(input()) last = [(0) for i in range(n + 1)] ubah = [(0) for i in range(q + 1)] for i in range(1, q + 1): k = input().split() if k[0] == "1": p = int(k[1]) x = int(k[2]) a[p - 1] = x last[p - 1] = i else: x = int(k[1]) ubah[i] = x for i in range(q - 1, -1, -1): ubah[i] = max(ubah[i + 1], ubah[i]) for i in range(n): print(max(a[i], ubah[last[i]]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) q = int(input()) a2 = [-1] * len(a) arr = [None] * q pay = [-1] * q for i in range(q): b = input().split() if len(b) == 2: pay[i] = int(b[1]) else: arr[i] = int(b[1]) a2[arr[i] - 1] = int(b[2]) pay_max = max(pay) pay_maxi = q - pay[::-1].index(pay_max) - 1 a = [(pay_max if x < pay_max else x) for x in a] m = [0] * q ma = -1 for i in range(q - 1, -1, -1): if pay[i] != -1: ma = max(ma, pay[i]) m[i] = ma for i in range(q): if arr[i]: if i > pay_maxi: a[arr[i] - 1] = max(a2[arr[i] - 1], m[i]) else: a[arr[i] - 1] = max(a2[arr[i] - 1], pay_max) print(*a)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = [[int(q), 0] for q in input().split()] k = int(input()) was, changes = 0, [] for _ in range(k): s = list(map(int, input().split())) if s[0] == 1: a[s[1] - 1] = [s[2], was] else: changes.append(s[1]) was += 1 max1 = [-1] for q in range(len(changes) - 1, -1, -1): max1.append(max(max1[-1], changes[q])) max1.reverse() print(*[max(q[0], max1[q[1]]) for q in a])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER LIST VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) init = [-1] + [int(x) for x in input().split()] Q = [tuple(map(int, input().split())) for q in range(int(input()))] p = [-1] * (n + 1) qmax = 0 for i in range(1, len(Q) + 1): q1 = Q[-i] if q1[0] == 2: qmax = max(qmax, q1[1]) elif p[q1[1]] == -1: p[q1[1]] = max(qmax, q1[2]) for i in range(1, n + 1): if p[i] == -1: p[i] = max(init[i], qmax) print(*p[1:])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) q = int(sys.stdin.readline()) qu = [tuple(map(int, sys.stdin.readline().split())) for _ in range(q)] an = [-1] * n m = 0 for i in range(q): query = qu[q - i - 1] if query[0] == 2: m = max(m, query[1]) elif an[query[1] - 1] == -1: an[query[1] - 1] = max(query[2], m) for i in range(n): if an[i] == -1: print(max(m, a[i]), end=" ") else: print(an[i], end=" ") print()
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
from sys import stdin inp = stdin.readline n = int(inp()) a = list(map(int, inp().split())) q = int(inp()) cur_max = 0 max_after_query = [0] * q queries = [] for i in range(q): op = list(map(int, inp().split())) queries.append(op) for i in range(q - 1, -1, -1): if queries[i][0] == 2 and cur_max < queries[i][1]: cur_max = queries[i][1] max_after_query[i] = cur_max for i in range(n): a[i] = max(cur_max, a[i]) for i in range(q): if queries[i][0] == 1: a[queries[i][1] - 1] = max(max_after_query[i], queries[i][2]) print(*a)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
INF = 10**12 n = int(input()) a = [int(item) for item in input().split()] min_recipt = [INF] * n q = int(input()) max_payoff = 0 query = [] for i in range(q): query.append([int(item) for item in input().split()]) ans = [-1] * n for que in query[::-1]: if que[0] == 1: if ans[que[1] - 1] != -1: continue ans[que[1] - 1] = max(max_payoff, que[2]) elif que[0] == 2: max_payoff = max(max_payoff, que[1]) for i, (val, item) in enumerate(zip(a, ans)): if item != -1: continue ans[i] = max(max_payoff, val) print(" ".join([str(item) for item in ans]))
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR NUMBER IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = list(map(int, input().split())) q = int(input()) r1 = [-1] * q r2 = [-1] * q for i in range(q): ne = list(map(int, input().split())) if ne[0] == 1: p = ne[1] - 1 t = ne[2] r1[i] = [p, t] else: r2[i] = ne[1] b = -1 for i in range(q - 1, -1, -1): b = max(b, r2[i]) r2[i] = b m = r2[0] for i in range(n): a[i] = max(a[i], m) for i in range(q): if r1[i] == -1: pass else: a[r1[i][0]] = max(r1[i][1], r2[i]) print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) q = int(input()) query = [(list(map(int, input().split())) + [i]) for i in range(q)] q1 = [] q2 = [0] * q for qu in query: if qu[0] == 1: q1.append(qu[1:]) else: q2[qu[-1]] = qu[1] MAXQ = [0] * q MAXQ[q - 1] = q2[q - 1] for i in range(q - 2, -1, -1): MAXQ[i] = max(MAXQ[i + 1], q2[i]) B = [(a, 0) for a in A] for x, y, ind in q1: B[x - 1] = y, ind ANS = [0] * n for i in range(n): m, ind = B[i] ANS[i] = max(m, MAXQ[ind]) print(*ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys sys.setrecursionlimit(10**5 + 1) inf = int(10**20) max_val = inf min_val = -inf RW = lambda: sys.stdin.readline().strip() RI = lambda: int(RW()) RMI = lambda: [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda: [x for x in sys.stdin.readline().strip().split()] nb = RI() have = RMI() nb_ops = RI() curr = [-1] * nb maxs = 0 ops = [RMI() for _ in range(nb_ops)][::-1] for i in ops: if i[0] == 2: maxs = max(maxs, i[1]) elif curr[i[1] - 1] == -1: curr[i[1] - 1] = max(maxs, i[2]) for i in range(nb): if curr[i] == -1: curr[i] = max(maxs, have[i]) print(*curr)
IMPORT EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) a = list(map(int, input().split())) last_updated = [(0) for _ in range(n)] q = int(input()) pay_days = [(0) for _ in range(q)] for i in range(q): qu = list(map(int, input().split())) if qu[0] == 1: _, p, x = qu a[p - 1] = x last_updated[p - 1] = i else: _, x = qu pay_days[i] = x for i in range(q - 1): pay_days[q - i - 2] = max(pay_days[q - i - 1], pay_days[q - i - 2]) for i in range(n): print(max(a[i], pay_days[last_updated[i]]), end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
n = int(input()) money = list(map(int, input().split())) q = int(input()) tranzactions = list(list(map(int, input().split())) for _ in range(q)) result = [-1] * n temp = -1 for i in range(q - 1, -1, -1): if tranzactions[i][0] == 1: if result[tranzactions[i][1] - 1] == -1: result[tranzactions[i][1] - 1] = max(tranzactions[i][2], temp) else: temp = max(tranzactions[i][1], temp) for i in range(n): if result[i] == -1: result[i] = max(temp, money[i]) print(" ".join(map(str, result)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $x$ are paid accordingly so that after the payout they have exactly $x$ money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the numer of citizens. The next line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 10^{9}$) — the initial balances of citizens. The next line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^{5}$) — the number of events. Each of the next $q$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($1 \le p \le n$, $0 \le x \le 10^{9}$), or 2 x ($0 \le x \le 10^{9}$). In the first case we have a receipt that the balance of the $p$-th person becomes equal to $x$. In the second case we have a payoff with parameter $x$. -----Output----- Print $n$ integers — the balances of all citizens after all events. -----Examples----- Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 -----Note----- In the first example the balances change as follows: 1 2 3 4 $\rightarrow$ 3 3 3 4 $\rightarrow$ 3 2 3 4 $\rightarrow$ 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 $\rightarrow$ 3 0 2 1 10 $\rightarrow$ 8 8 8 8 10 $\rightarrow$ 8 8 20 8 10
import sys class DWelfareState: def solve(self): n = int(input()) a = [int(_) for _ in input().split()] q = int(input()) queries = [] v = [[-1, a[i]] for i in range(n)] x_max = [-float("inf")] * (q + 1) for qi in range(q): query = [int(_) for _ in input().split()] queries.append(query) type = query[0] if type == 1: i, x = query[1:] i -= 1 v[i] = [qi, x] else: x = query[1] x_max[qi] = max(x_max[qi - 1], x) suff = [0] * (q + 1) suff[-1] = -float("inf") for i in range(q - 1, -1, -1): suff[i] = max(suff[i + 1], x_max[i]) ans = [0] * n for i in range(n): ans[i] = max(suff[v[i][0] + 1], v[i][1]) print(*ans) solver = DWelfareState() input = sys.stdin.readline solver.solve()
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR