description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
read = lambda: map(int, input().split()) n = int(input()) inf = 10**9 cur = inf a = [tuple(read()) for i in range(n)] dif = 0 def fail(): print("Impossible") exit() flag = True Min = -inf for i in range(n): c, d = a[i] if d == 2: flag = False if d == 2 and cur >= 1900: cur = 1899 if cur < Min: fail() if d == 1 and cur < 1900: fail() if d == 1: Min = max(Min, 1900) cur += c Min += c if flag: print("Infinity") exit() ans = cur print(ans)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
ans = 0 check1 = -9999999999 check2 = 9999999999 for i in range(int(input())): a, b = map(int, input().split()) if b == 1: if check2 < 1900: print("Impossible") exit() check1 = max(check1, 1900) + a check2 += a else: if check1 >= 1900: print("Impossible") exit() check2 = min(check2, 1899) + a check1 += a print("Infinity" if check2 >= 9979999999 else check2)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) for i in range(n): change, division = input().split() change = int(change) division = int(division) if i == 0: if division == 1: maxx = 10**15 minn = 1900 else: maxx = 1899 minn = -(10**10) if division == 1: if maxx < 1900: print("Impossible") return minn = max(minn, 1900) minn = minn + change maxx = maxx + change else: if minn >= 1900: print("Impossible") return maxx = min(maxx, 1899) minn = minn + change maxx = maxx + change if maxx > 10**10: print("Infinity") else: print(maxx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
def main(): n = int(input()) mn = -int(2000000000.0) mx = int(2000000000.0) impossible = False for i in range(n): c, d = [int(_) for _ in input().split()] if d == 1 and mx < 1900 or d == 2 and mn > 1899: impossible = True break if d == 1: mn = max(mn, 1900) else: mx = min(mx, 1899) mn += c mx += c if mn > mx: impossible = True break if impossible: print("Impossible") elif mx > 1000000000.0: print("Infinity") else: print(mx) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) minr = -1000000000000000000 maxr = 1000000000000000000 for i in range(n): c, div = [int(x) for x in input().split()] if div == 1: if minr < 1900: minr = 1900 elif maxr >= 1900: maxr = 1899 minr += c maxr += c if minr > maxr: print("Impossible") elif maxr > 10000000000: print("Infinity") else: print(maxr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
q = int(input()) q -= 1 a, s = map(int, input().split()) if s == 1: z = 1900 x = 9000000000 else: z = -9000000000 x = 1899 z += a x += a for j in range(0, q): a, s = map(int, input().split()) if s == 1: z = max(1900, z) else: x = min(1899, x) z += a x += a if x < z: print("Impossible") elif x >= 7000000000: print("Infinity") else: print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) mx = 10**9 mn = -mx p = 0 for i in range(n): c, d = [int(i) for i in input().split()] if d == 1: mn = max(mn, 1900 - p) else: mx = min(mx, 1899 - p) p += c if mx == 10**9: print("Infinity") elif mx >= mn: print(mx + p) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) c, d = map(int, input().split()) min_ = 0 max_ = 0 flag = True if d == 1: min_ = 1900 max_ = float("+Inf") else: min_ = float("-Inf") max_ = 1899 for i in range(n - 1): c1, d = map(int, input().split()) if d == 1: min_ = max(min_ + c, 1900) max_ += c else: max_ = min(max_ + c, 1899) min_ += c if min_ > max_: flag = False c = c1 min_ += c max_ += c if not flag: print("Impossible") elif max_ == float("+Inf"): print("Infinity") else: print(max_)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
from sys import * n = int(stdin.readline()) INF = 100000000000000000000000 MAX = 2 * INF MIN = -MAX possible = True for _ in range(n): c, d = stdin.readline().split(" ") c = int(c) d = int(d) if d is 1: MIN = max(MIN, 1900) if d is 2: MAX = min(MAX, 1899) if MIN > MAX: possible = False MIN += c MAX += c if not possible: print("Impossible") elif MAX > INF: print("Infinity") else: print(MAX)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
def main(): try: while True: n = int(input()) c = [0] * n d = [0] * n has_2 = False for i in range(n): c[i], d[i] = map(int, input().split()) if d[i] == 2: has_2 = True if not has_2: print("Infinity") continue minr = -(10**9) maxr = 10**9 for i in range(n): if d[i] == 1: minr = max(minr, 1900) else: maxr = min(maxr, 1899) if minr > maxr: print("Impossible") break minr += c[i] maxr += c[i] else: print(maxr) except EOFError: pass main()
FUNC_DEF WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) C = [] D = [] for i in range(n): c, d = list(map(int, input().strip().split())) C.append(c) D.append(d) flag = True if max(D) == min(D) and max(D) == 1: print("Infinity") else: if max(D) == min(D) and max(D) == 2: flag = False a = [] b = [] if D[0] == 1: a.append(0) else: b.append(0) currsum = 0 prefix_sums = [0] for i in range(1, n): currsum += C[i - 1] prefix_sums.append(currsum) if D[i] == 1: a.append(currsum) else: b.append(currsum) if flag: lowest_red_point = min(a) highest_blue_point = max(b) if flag and lowest_red_point <= highest_blue_point: print("Impossible") else: for i in range(n): if prefix_sums[i] == highest_blue_point: bp = i print(1899 + sum(C[bp:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) mx = 5 * 10**9 mn = -(10**9) flag = True for i in range(n): c, d = map(int, input().split()) if d == 1: mn = max(mn, 1900) else: mx = min(mx, 1899) if mn > mx: flag = False mn += c mx += c if not flag: print("Impossible") elif mx > 10**9: print("Infinity") else: print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
s, t = -(10**8), 10**8 for i in range(int(input())): c, d = map(int, input().split()) if d == 1: s = max(s, 1900) else: t = min(t, 1899) if s > t: print("Impossible") exit() s, t = s + c, t + c print("Infinity" if t > 5 * 10**7 else t)
ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER STRING VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) s = 10**10 x = s K = 1900 p = [] for i in range(n): c, d = map(int, input().split()) p.append([c, d]) if x >= K and d == 2: s -= x - (K - 1) x = K - 1 elif x < K and d == 1: s += K - x x = K x += c x = s ok = True for i in range(n): c, d = p[i] if (x < K) + 1 != d: ok = False x += c if not ok: print("Impossible") elif x > 10**9: print("Infinity") else: print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) r = [0] * n d = [0] * n for i in range(n): r[i], d[i] = map(int, input().split()) s = 0 a, b = float("infinity"), -float("infinity") for i in range(n): if d[i] == 1: a = min(a, s) else: b = max(b, s) s += r[i] ans = 1899 - b if ans >= float("infinity"): print("Infinity") elif b >= a: print("Impossible") else: print(ans + s)
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 VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) cdi = [[0, 0]] + [list(map(int, input().split())) for i in range(n)] for i in range(1, n + 1): cdi[i][0] += cdi[i - 1][0] cdi[i - 1][1] = cdi[i][1] cdi[-1][1] = 3 maxi = -(10**9) mini = 10**9 for i in range(n): if cdi[i][1] == 1: mini = min(mini, cdi[i][0]) else: maxi = max(maxi, cdi[i][0]) if maxi >= mini: print("Impossible") elif maxi == -(10**9): print("Infinity") else: print(1899 - maxi + cdi[-1][0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) A = [0] * n per = 0 ans1 = float("infinity") ans2 = -float("infinity") for j in range(n): per1, per2 = map(int, input().split()) if per2 == 1: if ans1 < 1900: per = 1 break else: ans2 = max(ans2, 1900) ans1 += per1 ans2 += per1 elif ans2 >= 1900: per = 1 break else: ans1 = min(ans1, 1899) ans1 += per1 ans2 += per1 if ans1 < ans2: per = 1 break if per == 0: if ans1 == float("infinity"): print("Infinity") else: print(ans1) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
import sys n = int(input()) change, m = 0, 0 s, t = -pow(10, 8), pow(10, 8) ar = [] rat, div = [], [] for i in range(n): c, d = map(int, input().split(" ")) div.append(d) ar.append(c) if d == 1: s = max(s, 1900) else: t = min(t, 1899) if s > t: print("Impossible") exit() s, t = s + c, t + c if d == 2: rat.append(change) change += c if len(rat) == 0: print("Infinity") else: print(1899 + (change - max(rat)))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
k = 9**9 t = [0, k, k] for i in range(int(input())): c, d = map(int, input().split()) d = 3 - 2 * d t[d] = min(t[d], t[0] * d) t[0] += c s, a, b = t print("Infinity" if b == k else "Impossible" if a != k and a + b < 1 else 1899 + s + b)
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP NUMBER VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) events = [] for line in range(n): c, d = map(int, input().split()) events.append((c, d)) if events[0][1] == 1: lb = 1900 ub = float("inf") else: lb = float("-inf") ub = 1899 def normalise_into(div): global lb, ub if div == 1 and lb < 1900: lb = 1900 if div == 1 and ub < 1900: return False if div == 2 and lb >= 1900: return False if div == 2 and ub >= 1900: ub = 1899 return True for a, b in zip(events, events[1:]): lb += a[0] ub += a[0] if not normalise_into(b[1]): print("Impossible") break else: lb += events[-1][0] ub += events[-1][0] print("Infinity" if ub == float("inf") else ub)
ASSIGN 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 IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR STRING STRING VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
n = int(input()) I = lambda: map(int, input().split()) t1 = 0 t2 = 0 j = 0 for _ in range(n): x, y = I() if y == 1: if t1 == 0: mi = j else: mi = min(mi, j) t1 += 1 else: if t2 == 0: ma = j else: ma = max(ma, j) t2 += 1 j += x if t1 == n: exit(print("Infinity")) elif t2 == n: exit(print(1899 - max(0, ma) + j)) eff1 = 1899 - ma eff2 = 1900 - mi if eff1 > eff2: exit(print(max(eff1, eff2) + j)) if eff1 == eff2: exit(print(eff1 + j)) else: exit(print("Impossible"))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
import sys sys.setrecursionlimit(5000000) def read(type=int): return type(input()) def read_arr(type=int): return [type(token) for token in input().split()] def abs(num): return num if num > 0 else -num inf = 10**9 c = 1899 u, l = inf, -inf diff = 0 n = read() A = [] for i in range(n): r, d = read_arr() A.append((r, d)) e = False for r, d in A: if d == 1: l = max(l, 1900 - diff) else: u = min(u, 1899 - diff) diff += r if u < l: e = True break if e or l > u: print("Impossible") elif u == inf: print("Infinity") else: print(u + diff)
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
def check(rating): r = rating for i in l: if rating <= 1899 and i[1] == 1: return "1" if rating >= 1900 and i[1] == 2: return "2" rating += i[0] nl.append(rating) return "1" n = int(input()) seen = set() l = [] for i in range(n): c, d = map(int, input().split()) seen.add(d) l.append([c, d]) nl = [] if len(seen) == 1 and 1 in seen: print("Infinity") else: s = 0 f = 0 onemin = float("inf") twomax = float("-inf") for i in l: if i[1] == 1: if s <= twomax: f = 1 break onemin = min(onemin, s) else: if s >= onemin: f = 1 break twomax = max(twomax, s) s += i[0] if f == 1: print("Impossible") else: if l[0][1] == 1: start = 1900 end = 2 * 10**7 + 1900 else: start = -(2 * 10**7 + 1900) end = 1899 while start <= end: mid = (start + end) // 2 ck = check(mid) if ck == "1": start = mid + 1 else: end = mid - 1 print(max(nl))
FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER NUMBER RETURN STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
[s, k] = [int(x) for x in input().split()] numbers = [1] numbers.append(1) last = 1 index = 1 while last <= s: l_index = index - k if l_index >= 0: last = last * 2 - numbers[l_index] else: last *= 2 if last <= s: numbers.append(last) index += 1 numbers.reverse() numbers.append(0) output = [] for i in numbers: if i <= s: s -= i output.append(i) print(len(output)) print(" ".join([str(x) for x in output]))
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = list(map(int, input().split(" "))) a = [0, 1, 1] while a[-1] < s: if len(a) < k: a.append(sum(a)) else: t = 0 for i in range(k): t += a[-i - 1] a.append(t) if s == a[-1]: print(2) print(0, a[-1]) else: use = [] for i in range(len(a)): if s >= a[-i - 1]: s -= a[-i - 1] use.append(a[-i - 1]) print(len(use)) for i in use: print(i, end=" ")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) fib = [0, 1] for i in range(80): g = 0 for x in range(k): if len(fib) - x - 1 < 0: break g += fib[len(fib) - x - 1] fib.append(g) ans = [] for x in reversed(fib): if x <= s: s -= x ans.append(x) print(len(ans)) print(" ".join(str(x) for x in ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = [int(i) for i in input().split()] a = [-1, 0, 1, 1] i = 3 while a[i] <= pow(10, 9): i += 1 a.append(0) if i <= k: for j in range(1, i): a[i] += a[j] else: for j in range(i - k, i): a[i] += a[j] b = [] for j in range(i, 0, -1): if a[j] <= s: b.append(a[j]) s -= a[j] if s == 0: b.append(0) break print(len(b)) for i in b: print(i, end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) f = [0] f.append(1) while True: cur = sum(f[-k:]) if cur > s: break f.append(cur) f = list(set(f)) f.sort() ans = [] i = len(f) - 1 while s and i > 0: if f[i] <= s: s -= f[i] ans.append(f[i]) i -= 1 print(len(ans) + 1) print(*(ans + [0]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST NUMBER
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) a, b = [0, 1], [] while a[-1] < s: a.append(sum(a[-k:])) for i in reversed(a): if i <= s: b.append(i) s -= i print(len(b)) print(" ".join(map(str, b)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER LIST WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
def genkbon(s, k): if k < 50: i = 0 res = [0] while res[i] <= s: if i < k: res.append(0) elif i == k: res.append(1) elif i == k + 1: res.append(1) else: res.append(2 * res[i] - res[i - k]) i += 1 del res[-1] return res if k >= 50: res = [0, 1] i = 1 while res[i] <= s: res.append(2 * res[i]) i += 1 return res def solve(s, k, tmp): tmp2 = tmp while tmp2[-1] > s: del tmp2[-1] if s == 0: return [0] if s == 1: return [0, 1] if s == 2: return [0, 2] ha = tmp2[-1] res = solve(s - ha, k, tmp2) return [ha] + res inp1 = input() inp = inp1.split() hlp = genkbon(int(inp[0]), int(inp[1])) sol = solve(int(inp[0]), int(inp[1]), hlp) print(len(sol)) for i in sol[:-1]: print(i, end=" ") print(sol[-1])
FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER WHILE VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN LIST NUMBER IF VAR NUMBER RETURN LIST NUMBER NUMBER IF VAR NUMBER RETURN LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = list(map(int, input().split())) a = [1] i = 0 while s > a[-1]: if i == 0: a.append(1) else: a.append(2 * a[-1] - int(a[-k - 1] if i >= k else 0)) i += 1 b = [] s0 = s while s > 0: l, r = -1, i + 1 while r - l > 1: m = (l + r) // 2 if a[m] >= s: r = m else: l = m r = min(i, r) while a[r] > s: r -= 1 s -= a[r] b.append(a[r]) if len(b) == 1: b.append(0) print(len(b)) print(*b)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
x, y = map(int, input().split()) dp = [] dp.append(0) dp.append(1) n = 2 while 1: sm = 0 for k in range(n - 1, n - y - 1, -1): if k == 0: break sm += dp[k] if sm > x: break dp.append(sm) n += 1 dp.reverse() res = [] n = 0 while n < len(dp) and x >= 0: if x >= dp[n]: res.append(dp[n]) x -= dp[n] n += 1 print(len(res)) print(*res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) f = [1] while f[-1] < s: x = 0 for i in range(max(0, len(f) - k), len(f)): x += f[i] f.append(x) result = [0] pos = len(f) - 1 while s != 0: while f[pos] > s: pos -= 1 result.append(f[pos]) s -= f[pos] print(len(result)) print(" ".join(map(str, result)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
def power(a, b): if b == 0: return 1 elif b % 2 == 0: a_1 = a * a return pow(a_1, b // 2) return a * pow(a, b - 1) def k_fib(s, k): result = [0] if k >= 40: fibs = [power(2, i) for i in range(40)] else: fibs = [0] * (k - 1) + [1] while fibs[len(fibs) - 1] < s: fibs.append(sum(fibs[-k:])) while s > 0: if fibs[len(fibs) - 1] <= s: result.append(fibs[len(fibs) - 1]) s -= fibs[len(fibs) - 1] fibs.pop() return result S, K = [int(j) for j in input().split()] print(len(k_fib(S, K))) print(*k_fib(S, K))
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
def s(): [s, k] = list(map(int, input().split())) d = [0] d.append(1) t = 0 r = [] while t < s: t = sum(d[-min(k, len(d)) :]) d.append(t) for i in reversed(d): if i <= s: s -= i r.append(i) if i == 0: break print(len(r)) print(*r) s()
FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) if k >= 32: k_bon = [0] for i in range(33): k_bon.append(2**i) else: k_bon = [0] * (k - 1) k_bon.append(1) i = k + 1 c = 0 while len(k_bon) <= 100: next = sum(k_bon[c:i]) k_bon.append(next) i += 1 c += 1 k_bon = set(k_bon) i = 0 ans = [] k_bon = sorted(list(k_bon)) while s != 0: if k_bon[i] >= s: if s == k_bon[i]: s -= k_bon[i] ans.append(k_bon[i]) i = 0 else: s -= k_bon[i - 1] ans.append(k_bon[i - 1]) i = 0 else: i += 1 if len(ans) == 1: ans.append(0) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
import sys input = sys.stdin.readline def sep(): return map(int, input().split()) def main(): s, k = sep() a = [0, 1] ans = [] while a[-1] < s: a.append(sum(a[-k:])) a.reverse() for i in a: if i <= s: ans.append(i) s -= i print(len(ans)) print(*ans) main()
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) F = [0, 1] b = set() while True: f = sum(F[-k:]) if f > s: break F.append(f) for i in reversed(F): if i <= s: b.add(i) s -= i print(len(b)) print(" ".join(map(str, b)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) p, t, l = [0], [0, 1, 1], 2 while t[l] < s: t.append((t[l] << 1) - (0 if l < k else t[l - k])) l += 1 t.reverse() for i in t: if i > s: continue p.append(i) s -= i if s == 0: break print(len(p)) print(" ".join(map(str, p)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER LIST NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
s, k = map(int, input().split()) arr = [0, 1] k1 = 1 visited = [] mini = 0 while arr[-1] < s: arr.append(sum(arr[-k:])) while s > 0: for i in arr: if i <= s: mini = i else: break s -= mini visited.append(mini) if len(visited) == 1: visited.append(0) print(len(visited)) print(*visited)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows: * F(k, n) = 0, for integer n, 1 ≤ n < k; * F(k, k) = 1; * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k. You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. Input The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1). Output In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Examples Input 5 2 Output 3 0 2 3 Input 21 5 Output 3 4 1 16
import sys input = sys.stdin.readline s, k = map(int, input().split()) ans = [] if k >= 60: f = [0, 1] x = 1 for i in range(60): f.append(x) x += x for i in range(60)[::-1]: if s >= f[i]: ans.append(f[i]) s -= f[i] if s == 0: break else: f = [0] * (k - 1) + [1] x = 1 for i in range(60): f.append(x) y = x - f[i] x += y ans = [] for i in range(60)[::-1]: if s >= f[i]: ans.append(f[i]) s -= f[i] if s == 0: break ans.append(0) print(len(ans)) print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def main(): n, r, avg = map(int, input().split()) exams = [] total = 0 for i in range(n): a, b = map(int, input().split()) exams.append((a, b)) total += a if total / n >= avg: print(0) return exams = sorted(exams, key=lambda x: x[1]) ans = 0 for i in range(n): a, b = exams[i][0], exams[i][1] x = n * avg - total ans += min(x, r - a) * b total += min(x, r - a) if total / n >= avg: break print(ans) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def main(): n, r, avg = map(int, input().split(" ")) grade = [] sumIp = 0 for i in range(n): grade.append([int(item) for item in input().split(" ")]) sumIp += grade[i][0] grade.sort(key=takeSecond) i = 0 aimSum = avg * n essays = 0 points = 0 while sumIp < aimSum and i < n: if grade[i][0] < r: points = min(r - grade[i][0], aimSum - sumIp) essays += points * grade[i][1] sumIp += points i += 1 print(essays) def takeSecond(item): return item[1] main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
__author__ = "PrimuS" n, r, a = (int(x) for x in input().split()) marks = [[0, 0]] * n s = 0 for i in range(n): ss = input() marks[i] = [int(x) for x in ss.split()] s += marks[i][0] if s / n >= a: print(0) else: x = a * n - s def ccmp(b): return b[1] marks.sort(key=ccmp) i = 0 res = 0 while x > 0: y = min(x, r - marks[i][0]) x -= y res += marks[i][1] * y i += 1 print(res)
ASSIGN VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) x = [] s = 0 for i in range(n): a, b = map(int, input().split()) s += a x.append((a, b)) rem = avg * n - s x.sort(key=lambda i: i[1]) i = 0 count = 0 while rem > 0: if x[i][0] < r: v = min(rem, r - x[i][0]) count += v * x[i][1] rem -= v i += 1 print(count)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) lst = [] c = 0 for i in range(n): lst.append(list(map(int, input().split()))) def aver(li): s = sum(x for x, y in li) return s / len(lst) if aver(lst) < avg: lst = sorted(lst, key=lambda x: x[1]) x = avg * len(lst) - sum(k for k, p in lst) for f, s in lst: if r - f < x: c += s * (r - f) x -= r - f else: c += x * s break print(c) else: print(0)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) arr, s = [], 0 for i in range(n): arr.append(list(map(int, input().split()))) s += arr[-1][0] arr = sorted(arr, key=lambda x: x[1]) res = 0 for i in range(n): if min(n * avg - s, r - arr[i][0]) > 0: res += min(n * avg - s, r - arr[i][0]) * arr[i][1] s += min(n * avg - s, r - arr[i][0]) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
line = input().split(" ") n = int(line[0]) r = int(line[1]) avg = int(line[2]) class Exam: def __init__(self, a, b): self.a = a self.b = b def __repr__(self): return repr((self.a, self.b)) i = 0 s = 0 lst = [] while i < n: line = input().split(" ") a = int(line[0]) b = int(line[1]) lst.append(Exam(a, b)) s += a i += 1 lst.sort(key=lambda exam: exam.b) ans = 0 avg *= n for exam in lst: if s >= avg: break ans += min(r - exam.a, avg - s) * exam.b s += min(r - exam.a, avg - s) print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) goal = n * avg essay = 0 V = [] for i in range(n): a, b = map(int, input().split()) goal -= a V.append([b, a]) V.sort() goal = [0, goal][goal > 0] for j in V: if not goal: break else: m = min(r - j[1], goal) essay += j[0] * m goal -= m print(essay)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, a = [int(x) for x in input().split()] exams = [] grades = 0 essays = 0 for i in range(n): grade, essay = [int(x) for x in input().split()] grades += grade exams.append([grade, essay]) if grades >= n * a: print(0) else: exams.sort(key=lambda x: x[1]) needs = n * a - grades while needs > 0: for i in exams: essays += min(needs, r - i[0]) * i[1] needs -= min(needs, r - i[0]) print(essays)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR WHILE VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) ab = [0] * n for i in range(n): a, b = map(int, input().split()) ab[i] = b, a ab.sort() summ = avg * n summ1 = 0 res = 0 for i in range(n): summ1 += ab[i][1] for i in range(n): dif = summ - summ1 now = r - ab[i][1] if dif <= 0: break if now >= dif: res += dif * ab[i][0] summ1 = summ else: res += now * ab[i][0] summ1 = summ1 + now print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = list(map(int, input().split())) notas = [list(map(int, input().split()))[::-1] for x in range(n)] notas.sort() i = 0 soma = [sum(i) for i in zip(*notas)][1] essays = 0 while soma < avg * n and i < n: dif = r - notas[i][1] precisa = avg * n - soma if dif > precisa: dif = precisa if dif > 0: soma += dif notas[i][1] += dif essays += dif * notas[i][0] else: i += 1 print(essays)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) exams = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[1]) goal = avg * n current = sum([exam[0] for exam in exams]) essays = 0 if current < goal: for exam in exams: a, b = exam points = r - a if current + points <= goal: more_essays = points * b essays += more_essays current += points else: points = goal - current essays += points * b break print(essays)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def exponent_mod(n, p, prime_const=1000000000 + 7): res = 1 if n == 0: return 0 while p > 0: if p % 2 == 1: res = res * n % prime_const p //= 2 n = n * n % prime_const return res def find_min_essays(n, r, avg, essays): times = 0 count = 0 s = 0 required = 0 for grade, essay in essays: s += grade if s < n * avg: required = n * avg - s essays.sort(key=lambda x: x[1]) for grade, essay in essays: times = min(r - grade, required) count += essay * times required -= times return count t = 1 while t: t -= 1 prime_const = pow(10, 9) + 7 values = list(map(int, input().strip().split()))[:3] n = values[0] r = values[1] avg = values[2] essays = [] for i in range(n): items = list(map(int, input().strip().split()))[:2] essays.append([items[0], items[1]]) print(find_min_essays(n, r, avg, essays))
FUNC_DEF BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
import time n, r, avg = (int(i) for i in input().split()) exams = [] ref = 0 for i in range(n): a, b = (int(i) for i in input().split()) exams.append([r - a, b]) start = time.time() add = (avg - r) * n + sum(i[0] for i in exams) if add > 0: exams = sorted(exams, key=lambda x: x[::-1]) ref = 0 for i in exams: if add > i[0]: ref += i[0] * i[1] else: ref += add * i[1] add -= i[0] if add <= 0: break print(ref) finish = time.time()
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, a = map(int, input().split()) ab = [] for i in range(n): ab.append(list(map(int, input().split()))) def f(v): return v[1] ab.sort(key=f) a *= n for i in ab: a -= i[0] if a <= 0: print(0) else: i = 0 ct = 0 while a != 0: if r - ab[i][0] <= a: ct += (r - ab[i][0]) * ab[i][1] a -= r - ab[i][0] else: ct += a * ab[i][1] break i += 1 print(ct)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) exam = [] need_score = n * avg ret = 0 for _ in range(n): a, b = map(int, input().split()) need_score -= a if a == r: continue else: exam.append([b, r - a]) exam.sort(key=lambda x: x[0]) for e in exam: if need_score <= 0: break cnt = min(need_score, e[1]) need_score -= cnt ret += cnt * e[0] print(ret)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) lst = [[0, 0]] * n score = 0 for x in range(n): lst[x] = list(map(int, input().split())) score += lst[x][0] lst.sort(key=lambda x: x[1]) scoreRequird = n * avg - score essays = 0 i = 0 while scoreRequird > 0 and i < len(lst): if lst[i][0] < r: increment = min(r - lst[i][0], scoreRequird) scoreRequird -= increment lst[i][0] += increment essays += lst[i][1] * increment else: i += 1 print(essays)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
import sys def read(line): return [int(c) for c in line.strip().split()] def main(): test = sys.stdin.readlines() n, r, avg = read(test[0]) grades = [read(test[i]) for i in range(1, n + 1)] grades.sort(key=lambda x: x[1]) cur_sum = sum(g[0] for g in grades) required_sum = avg * len(grades) i = 0 ans = 0 while cur_sum < required_sum: diff = required_sum - cur_sum max_inc = r - grades[i][0] if max_inc <= diff: ans += grades[i][1] * max_inc cur_sum += max_inc else: ans += grades[i][1] * diff break i += 1 print(ans) main()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) s = 0 l = [] for i in range(n): a, b = map(int, input().split()) l.append([b, a]) s += a l.sort() z = s yo = n * avg - z if yo <= 0: print(0) exit() ans = 0 for i in range(n): b, a = l[i] if r - a > yo: ans += yo * b yo = 0 break else: ans += (r - a) * b yo -= r - a print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def f(): n, r, t = map(int, input().split()) t, p = t * n, {} s = k = 0 for i in range(n): a, b = map(int, input().split()) s += a if a == r: continue p[b] = p.get(b, 0) + r - a if s < t: for b in sorted(p.keys()): d = p[b] if d < t - s: s += d k += d * b else: return k + (t - s) * b return 0 print(f())
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
inp = [int(x) for x in input().split()] n = inp[0] r = inp[1] avg = inp[2] exams = [[int(x) for x in input().split()] for x in range(n)] exams.sort(key=lambda x: x[1]) examsSum = 0 for x in exams: examsSum += x[0] missingPoints = avg * n - examsSum assigments = 0 i = 0 while missingPoints > 0: if r == exams[i][0]: i += 1 continue availablePoints = r - exams[i][0] points = availablePoints if availablePoints <= missingPoints else missingPoints assigments += points * exams[i][1] missingPoints -= points i += 1 print(assigments)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) arr = [] summ = 0 for i in range(n): a, b = map(int, input().split()) summ += a arr.append([a, b]) need = n * avg - summ if need == 0: print(0) else: ans1 = 0 arr = sorted(arr, key=lambda x: x[1]) for i in range(n): if arr[i][0] < r and need > 0: add = r - arr[i][0] if need >= add: need -= add else: m = add - need add -= m need -= add ans1 += add * arr[i][1] if need == 0: break print(ans1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) l = [] s = 0 for i in range(n): k = [] a, b = map(int, input().split()) s += a k.append(b) k.append(a) l.append(k) lp = avg * n - s l.sort() i = 0 nes = 0 while lp > 0: slp = r - l[i][1] mi = min(lp, slp) nes += mi * l[i][0] lp -= mi i += 1 print(nes)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
t = input().split() n = int(t[0]) r = int(t[1]) avg = int(t[2]) a = [] for i in range(n): a.append(input().split()) t = int(a[i][0]) a[i][0] = int(a[i][1]) a[i][1] = t a = sorted(a) ref = 0 new = 0 for i in range(n): new += a[i][1] new /= n i = 0 while new < avg and i < n: x = min(r - a[i][1], round((avg - new) * n)) new += 1 / n * x ref += a[i][0] * x i += 1 print(round(ref))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
import sys n, r, avg = map(int, sys.stdin.readline().split()) arr = [] for i in range(n): x, y = map(int, sys.stdin.readline().split()) arr.append([y, x]) s = 0 for i in range(n): s += arr[i][1] if s >= avg * n: print(0) else: grades_needed = avg * n - s arr.sort() ans = 0 i = 0 while grades_needed > 0: t = min(grades_needed, r - arr[i][1]) ans += t * arr[i][0] grades_needed -= t i += 1 print(ans)
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, p = map(int, input().split()) t = [] for i in range(n): t.append(list(map(int, input().split()))) def func(n): return n[1] t = sorted(t, key=func) s = 0 e = 0 for i in range(len(t)): s += t[i][0] for i in t: if s >= p * n: break if i[0] < r: if s + r - i[0] < p * n: s += r - i[0] e += (r - i[0]) * i[1] else: e += (p * n - s) * i[1] break print(e)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR IF VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
line = input().split() n, r, avg = int(line[0]), int(line[1]), int(line[2]) exams = [] total, to_add, points = avg * n, avg * n, 0 for i in range(n): ex = input().split() exams.append((int(ex[0]), int(ex[1]))) exams = sorted(exams, key=lambda t: t[1]) for exam in exams: to_add -= exam[0] if to_add > 0: for exam in exams: if to_add > 0: points += min(r - exam[0], to_add) * exam[1] to_add -= r - exam[0] else: break else: print("0") exit() print(points)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) m = [] for i in range(n): g = list(map(int, input().split())) m.append(g) total = avg * n marks = 0 for i in range(n): marks += m[i][0] req = total - marks if req <= 0: print(0) else: b = [] for i in range(n): b.append(m[i][1]) a = [0] * (max(b) + 1) for i in range(n): x = r - m[i][0] a[m[i][1]] += x cnt = 0 for i in range(max(b) + 1): req -= a[i] if req > 0: cnt += a[i] * i else: cnt += (a[i] + req) * i break print(cnt)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) arr = [tuple(map(int, input().split())) for _ in range(n)] arr.sort(key=lambda x: x[1]) diff = n * avg - sum([x[0] for x in arr]) c = 0 if diff > 0: for i in range(n): x = min(diff, r - arr[i][0]) c += x * arr[i][1] diff -= x if diff == 0: break print(c)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) total = 0 exams = [] for i in range(n): score, cost = map(int, input().split()) total += score exams.append((cost, score)) need = n * avg - total result = 0 exams.sort() for cost, score in exams: if need <= 0: break x = min(need, r - score) result += cost * x need -= x print(result)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, mi = map(int, input().split()) l = [] t = 0 k = 0 for i in range(n): a, b = map(int, input().split()) if r - a > 0: l.append([b, r - a]) t = t + a if r - a <= 0: t = t + a V = mi * n - t l = sorted(l) for x in l: if V > 0: k = k + min(V, x[1]) * x[0] V = V - min(V, x[1]) print(k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
ab = [] total_a = 0 points = 0 n, r, avg = [int(_) for _ in input().split()] for _ in range(n): a, b = [int(_) for _ in input().split()] ab.append((a, b)) total_a = total_a + a avg_a = total_a // n if avg <= avg_a: print(0) exit(0) else: points = avg * n - total_a ab = sorted(ab, key=lambda x: x[1]) ans = 0 for index, elem in enumerate(ab): to_r = r - elem[0] ans = ans + min(points, to_r) * elem[1] points -= to_r if points <= 0: break print(ans)
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def solve(n, r, avg, grades): grades.sort(key=lambda x: (x[1], x[0])) vanyas = sum(a for a, b in grades) remaining = avg * n - vanyas written = 0 for a, b in grades: if remaining <= 0: break else: win = int(min(r - a, remaining)) written += b * win remaining -= win return written if remaining <= 0 else -1 def main(): n, r, avg = map(int, input().split()) grades = [] for _ in range(n): a, b = map(int, input().split()) grades.append((a, b)) res = solve(n, r, avg, grades) print(res) main()
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = list(map(int, input().rstrip().split())) sub = [] mark = 0 for i in range(n): x, y = list(map(int, input().rstrip().split())) sub.append([x, y]) mark += x marks = avg * n sub.sort(key=lambda x: x[1]) i = 0 ans = 0 while mark < marks: x = min(marks - mark, r - sub[i][0]) mark += x ans += x * sub[i][1] i += 1 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) t = avg * n l = [] num = 0 ans = 0 for i in range(n): a, b = map(int, input().split()) num += a l.append((b, r - a)) l = sorted(l) i = 0 while num < t: left = t - num tmp = min(left, l[i][1]) ans += tmp * l[i][0] num += tmp i += 1 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def main(): n, r, avg = map(int, input().split()) need = avg * n d = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) cur = sum(x[0] for x in d) ret = 0 left = need - cur if left <= 0: return 0 for x in d: can = min(r - x[0], left) ret += can * x[1] left -= can if left == 0: return ret print(main())
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
import sys sys.setrecursionlimit(10**8) try: FILE_POINTER = open("input.inpt") input = FILE_POINTER.readline except: FILE_POINTER = None input = sys.stdin.readline n, r, av = list(map(int, input().strip().split())) grades = [] curr = 0 for i in range(n): grades.append(list(map(int, input().strip().split()))) curr += grades[-1][0] require = av * n grades.sort(key=lambda x: x[1]) i = 0 ans = 0 while curr < require: if grades[i][0] < r: increment = min(require - curr, r - grades[i][0]) ans += grades[i][1] * increment curr += increment i += 1 print(ans) if FILE_POINTER: FILE_POINTER.close()
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
array = list(map(int, input().rstrip().split())) n = array[0] r = array[1] avg = array[2] minmmarks = n * avg marks = 0 List = [] for i in range(n): ab = list(map(int, input().rstrip().split())) marks += ab[0] ab.reverse() List += [ab] if marks >= minmmarks: print(0) else: required = minmmarks - marks List.sort() essay = 0 for i in range(n): if r - List[i][1] >= required: essay += required * List[i][0] print(essay) break else: essay += (r - List[i][1]) * List[i][0] required -= r - List[i][1]
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER 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 VAR VAR NUMBER EXPR FUNC_CALL VAR VAR LIST VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) avg *= n a = [0] * 1000001 b = [0] * 1000001 av = 0 for i in range(n): c, d = map(int, input().split()) av += c a[d] += c b[d] += 1 es = 0 for i in range(1000001): if av < avg and b[i] > 0: es += min(b[i] * r - a[i], avg - av) * i av += min(b[i] * r - a[i], avg - av) elif av >= avg: print(es) exit(0) print(es)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def main(): n, r, a = map(int, input().split()) a *= n tab = [] for x in range(n): ga, b = map(int, input().split()) tab.append((ga, b)) a -= ga if a <= 0: print(0) return tab.sort(key=lambda x: x[1]) inc = 0 for x in range(n): if a - (r - tab[x][0]) <= 0: inc += a * tab[x][1] break else: inc += (r - tab[x][0]) * tab[x][1] a -= r - tab[x][0] print(inc) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR 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 VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
from sys import stdin, stdout class Grade: a, b = 0, 0 def __lt__(self, other): return self.b < other.b n, r, avg = map(int, stdin.readline().split()) grade, add, cnt = [Grade() for i in range(n)], 0, 0 for i in range(n): grade[i].a, grade[i].b = map(int, stdin.readline().split()) add += grade[i].a grade.sort() add = n * avg - add if n * avg - add > 0 else 0 for i in range(n): if add - r + grade[i].a >= 0: add -= r - grade[i].a cnt += grade[i].b * (r - grade[i].a) else: cnt += grade[i].b * add break stdout.write("%d" % cnt)
CLASS_DEF ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, a = [int(x) for x in input().split()] m = [[int(x) for x in input().split()] for _ in range(n)] m.sort(key=lambda x: x[1]) s = n * a l = sum(m[i][0] for i in range(n)) c = 0 for j in range(n): if l + r - m[j][0] < s: c += (r - m[j][0]) * m[j][1] l += r - m[j][0] else: c += max(s - l, 0) * m[j][1] break print(c)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
import sys input = sys.stdin.readline def multi_input(): return map(int, input().split()) def array_print(arr): print(" ".join(map(str, arr))) total = ans = 0 marks = [] n, r, avg = multi_input() req_total = n * avg for i in range(n): a, b = multi_input() total += a marks.append([a, b]) marks.sort(key=lambda item: item[1]) if req_total > total: for i in marks: if i[0] < r: temp = min(r - i[0], req_total - total) total += temp ans += temp * i[1] if req_total == total: break print(ans) else: print(0)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = list(map(int, input().split())) score = [] total = 0 for i in range(n): a, b = list(map(int, input().split())) score.append((b, a)) total += a need_point = max(0, avg * n - total) score.sort() ans = 0 for b, a in score: if need_point == 0: break if a < r: ans += b * min(r - a, need_point) need_point -= min(r - a, need_point) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) l = [] grade = 0 for i in range(n): a, b = map(int, input().split()) l.append([b, a]) grade += a reqd = n * avg - grade if reqd < 1: print(0) exit() l.sort() i = 0 ans = 0 while reqd > 0: if reqd > r - l[i][1]: ans += l[i][0] * (r - l[i][1]) reqd -= r - l[i][1] i += 1 else: ans += l[i][0] * reqd reqd = 0 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) avg *= n l = [] s = 0 for i in range(n): a, b = map(int, input().split()) s += a l.append((b, a)) l = sorted(l) req = 0 i = 0 while i < n and s < avg: take = min(r - l[i][1], avg - s) s += take req += take * l[i][0] i += 1 print(req)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
__author__ = "Rakshak.R.Hegde" n, r, avg = map(int, input().split()) ab = [] d = n * avg for i in range(n): a, b = map(int, input().split()) d -= a ab.append((b, a)) ab.sort() cost = 0 for t in ab: if d <= 0: break if t[1] < r: m = min(d, r - t[1]) cost += m * t[0] d -= m print(cost)
ASSIGN VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) lst = [] ans = 0 s = n * avg for i in range(n): x = input().split() lst.append([int(x[1]), int(x[0])]) s -= int(x[0]) lst.sort() for j in lst: if s <= 0: break tem = min(s, r - j[1]) ans += tem * j[0] s -= tem print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, a = map(int, input().split(" ")) s = 0 arr = [] for _ in range(n): u, v = map(int, input().split(" ")) if u < r: arr.append([u, v]) s = s + u x = n * a - s if x <= 0: ans = 0 else: ans = 0 arr.sort(key=lambda x: x[1]) for item in arr: if r - item[0] < x: ans = ans + (r - item[0]) * item[1] x = x - (r - item[0]) else: ans = ans + x * item[1] x = 0 if x == 0: break print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
__author__ = "Ekaterina" n, r, avg = (int(m) for m in input().split()) exams = [] for i in range(n): input_i = [int(m) for m in input().split()] exams.append([input_i[1], input_i[0]]) exams.sort() current_sum = exams[0][1] works_to_do = 0 for x in range(1, n): current_sum += exams[x][1] needed_points = avg * n - current_sum if needed_points <= 0: print(0) else: j = 0 while needed_points > 0: points_subject = r - exams[j][1] if needed_points == points_subject: works_to_do = works_to_do + exams[j][0] * points_subject break elif needed_points < points_subject: works_to_do = works_to_do + exams[j][0] * needed_points break elif needed_points > points_subject: needed_points = needed_points - points_subject works_to_do = works_to_do + exams[j][0] * points_subject j += 1 print(works_to_do)
ASSIGN VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) a = [] for i in range(n): p, q = map(int, input().split()) a.append((q, p)) def sortFirst(val): return val[0] a.sort(key=sortFirst) jog = 0 for i in range(n): jog += a[i][1] k = n * avg - jog if k <= 0: print(0) else: ans = 0 x = 0 for i in range(n): x += r - a[i][1] if x <= k: ans += (r - a[i][1]) * a[i][0] else: if i != 0: x -= r - a[i][1] ans += (k - x) * a[i][0] else: ans += k * a[i][0] break print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
N, R, avg = map(int, input().split()) q = [] ttla = 0 for i in range(N): a, b = map(int, input().split()) ttla += a q.append((b, R - a)) rest = N * avg - ttla q.sort() ans = 0 for cost, times in q: if rest <= 0: break if rest < times: ans += cost * rest rest = 0 else: ans += cost * times rest -= times print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
def mergesort(arr, sup): if len(arr) > 1: mid = len(arr) // 2 left = arr[:mid] right = arr[mid:] leftsup = sup[:mid] rightsup = sup[mid:] mergesort(left, leftsup) mergesort(right, rightsup) i = j = k = 0 while i < len(left) and j < len(right): if left[i] < right[j]: arr[k] = left[i] sup[k] = leftsup[i] i += 1 else: arr[k] = right[j] sup[k] = rightsup[j] j += 1 k += 1 while i < len(left): arr[k] = left[i] sup[k] = leftsup[i] i += 1 k += 1 while j < len(right): arr[k] = right[j] sup[k] = rightsup[j] j += 1 k += 1 return arr, sup def swap(i, j, a, b): a[i], a[j] = a[j], a[i] b[i], b[j] = b[j], b[i] try: n, r, avg = map(int, input().split()) a, b = [], [] sum, diff, ans = 0, 0, 0 for _ in range(n): ai, bi = map(int, input().split()) a.append(ai) b.append(bi) sum += ai if sum >= n * avg: print(0) exit() else: diff = n * avg - sum b, a = mergesort(b, a) for i in range(len(a)): if diff == 0: break if r - a[i] > 0: if r - a[i] <= diff: ans = ans + (r - a[i]) * b[i] diff -= r - a[i] else: ans = ans + diff * b[i] diff = 0 print(ans) except EOFError as e: pass
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = [int(i) for i in input().split()] li = [] for i in range(n): tmp = [int(i) for i in input().split()] li.append([tmp[1], tmp[0]]) li.sort(reverse=True) dis = avg * n - sum([i[1] for i in li]) ans = 0 while dis > 0: exam = li.pop() if dis <= r - exam[1]: ans += exam[0] * dis dis = 0 else: ans += exam[0] * (r - exam[1]) dis -= r - exam[1] print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = [int(x) for x in input().split()] l = [] for i in range(n): l.append([int(x) for x in input().split()][::-1]) l.sort() need = avg * n have = sum(x[1] for x in l) ans = 0 for a, b in l: ans += max(min(need - have, r - b), 0) * a have += max(min(need - have, r - b), 0) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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 VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
sm = 0 n, r, avg = map(int, input().split()) marks = [] for i in range(n): a, b = map(int, input().split()) marks.append([a, b]) sm += a req = avg * n - sm cost = 0 if req <= 0: print(0) exit() marks.sort(key=lambda x: x[1]) for i in range(n): if marks[i][0] >= r: continue if req == 0: continue rem = r - marks[i][0] if req >= rem: cost += marks[i][1] * rem req -= rem elif req < rem: cost += marks[i][1] * req req = 0 if req: print(-1) else: print(cost)
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) arr = [] k = 0 for i in range(n): a, b = map(int, input().split()) arr.append([a, b]) diff = avg * n - sum(i[0] for i in arr) if diff <= 0: print(k) else: arr = sorted(arr, key=lambda x: x[1]) for i in arr: if diff == 0: break else: d = min(diff, r - i[0]) diff -= d k += d * i[1] if diff == 0: print(k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
import sys def In(): return map(int, sys.stdin.readline().split()) def exams(): n, r, avg = In() req = n * avg tol = 0 l = [] for _ in range(n): new, m = In() l.append([new, m]) tol += new if tol > req: return 0 l.sort(key=lambda x: x[1]) ans = 0 for i in range(n): now = l[i] if r - now[0] > req - tol: ans += (req - tol) * now[1] break ans += (r - now[0]) * now[1] tol += r - now[0] return ans print(exams())
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
n, r, avg = map(int, input().split()) cost_mark = [] for _ in range(n): mark, cost = map(int, input().split()) cost_mark += [[cost, mark]] cost_mark = sorted(cost_mark) current_sum = sum([x[1] for x in cost_mark]) needed_sum = max(n * avg - current_sum, 0) needed_essays = 0 for cost, mark in cost_mark: if needed_sum - (r - mark) > 0: needed_sum -= r - mark needed_essays += (r - mark) * cost else: needed_essays += needed_sum * cost needed_sum = 0 break print(needed_essays)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR