description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def getKey(item):
return item[0]
n, d = map(int, input().split())
li = []
for _ in range(n):
l = [int(x) for x in input().split()]
li.append(l)
li = sorted(li, key=getKey)
mx = -1
sum = [0] * n
sum[0] = li[0][1]
for i in range(1, n):
sum[i] = sum[i - 1] + li[i][1]
end = 0
for i in range(0, n):
tmp = end
for j in range(tmp, n):
if li[j][0] - li[i][0] < d:
end = j
else:
break
cnt = li[i][1]
if end > i and i == 0:
cnt = sum[end]
elif end > i:
cnt = sum[end] - sum[i - 1]
if cnt > mx:
mx = cnt
print(mx)
|
FUNC_DEF RETURN VAR NUMBER ASSIGN 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
values = []
for i in range(n):
m, f = input().split()
values.append((int(m), int(f)))
values.sort()
l, r = 0, 1
ans, curr = values[0][1], values[0][1]
while r < n:
curr += values[r][1]
while l < r and values[r][0] - values[l][0] >= d:
curr -= values[l][1]
l += 1
ans = max(ans, curr)
r += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def max_friendship_factor(friends, min_money_diff):
sorted_friends = sorted(friends, key=lambda t: t[0])
n = len(friends)
_, ff_sum = sorted_friends[0]
max_ff_sum = ff_sum
head_index = 0
hm, hff = sorted_friends[0]
for i in range(1, n):
m, ff = sorted_friends[i]
ff_sum += ff
while abs(m - hm) >= min_money_diff:
ff_sum -= hff
head_index += 1
hm, hff = sorted_friends[head_index]
if max_ff_sum < ff_sum:
max_ff_sum = ff_sum
return max_ff_sum
def run_alg():
first_line_data = input().split(" ")
num_friends = int(first_line_data[0])
min_money_diff = int(first_line_data[1])
friends = []
for _ in range(num_friends):
line_data = input().split(" ")
money = int(line_data[0])
friendship = int(line_data[1])
friends.append((money, friendship))
print(max_friendship_factor(friends, min_money_diff))
run_alg()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def sortam(t):
return t[0]
def sortamPrim(t):
return t[1]
s = input().split()
n = int(s[0])
d = int(s[1])
bani_prietenie = []
for i in range(n):
s = input().split()
bani_prietenie.append((int(s[0]), int(s[1])))
bani_prietenie.sort(key=sortamPrim)
bani_prietenie.sort(key=sortam)
st = 0
dr = -1
s = 0
maximum = 0
while st < n:
while dr + 1 < n and bani_prietenie[dr + 1][0] - bani_prietenie[st][0] < d:
dr += 1
s += bani_prietenie[dr][1]
maximum = max(maximum, s)
s -= bani_prietenie[st][1]
st += 1
print(maximum)
|
FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = sorted(list(map(int, input().split())) for _ in range(n))
friendship, highest, i = 0, 0, 0
for j in range(n):
friendship += friends[j][1]
while friends[j][0] - friends[i][0] >= d:
friendship -= friends[i][1]
i += 1
highest = max(highest, friendship)
print(highest)
|
ASSIGN 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 ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def solve(n, d, f):
f.sort(key=lambda x: (x[0], -x[1]))
left = 0
right = 1
s = f[left][1]
c = s
while right < len(f):
m = f[right][0] - f[left][0]
if m < d:
c = c + f[right][1]
s = max(s, c)
right += 1
else:
c = c - f[left][1]
left += 1
return s
def main():
n, d = map(int, input().split())
f = []
for i in range(n):
f.append(list(map(int, input().split())))
print(solve(n, d, f))
main()
|
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
arr = []
for i in range(n):
arr.append(tuple(map(int, input().split())))
arr = sorted(arr)
prefix = []
prefix.append(arr[0][1])
for i in range(1, n):
prefix.append(prefix[i - 1] + arr[i][1])
ans = 0
for i in range(n):
low = 0
high = n - 1
while low < high:
mid = (low + high + 1) // 2
if arr[mid][0] >= arr[i][0] + d:
high = mid - 1
else:
low = mid
if i == 0:
ans = prefix[low]
elif prefix[low] - prefix[i - 1] > ans:
ans = prefix[low] - prefix[i - 1]
print(ans)
|
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().strip().split())
arr = [tuple(map(int, input().strip().split())) for i in range(n)]
arr.sort()
last = 0
max_score = 0
curr_score = 0
for money, friendship in arr:
if money >= last + d:
max_score = max(max_score, curr_score)
curr_score = friendship
last = money
else:
curr_score += friendship
max_score = max(max_score, curr_score)
print(max_score)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
l = []
for i in range(n):
a, b = map(int, input().split())
l.append([a, b])
l.sort()
ans = l[0][1]
c = l[0][1]
i = 0
j = 1
while j < n:
if l[j][0] - l[i][0] < d:
c += l[j][1]
j += 1
else:
c -= l[i][1]
i += 1
ans = max(ans, c)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
a.sort()
p1 = p2 = 0
ma = 0
su = 0
while p2 < n:
if a[p2][0] - a[p1][0] < d:
su += a[p2][1]
p2 += 1
ma = max(ma, su)
else:
su -= a[p1][1]
p1 += 1
print(ma)
|
ASSIGN 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = dict()
for _ in range(n):
k, v = map(int, input().split())
if k in friends:
friends[k] += v
else:
friends[k] = v
ans = 0
tmp = i = j = 0
keys = sorted(friends.keys())
vals = [friends[k] for k in keys]
while j < len(keys):
while j < len(keys) and keys[j] - keys[i] < d:
tmp += vals[j]
j += 1
ans = max(ans, tmp)
tmp -= vals[i]
i += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, dr = (int(i) for i in input().split())
a = []
for i in range(n):
b = [int(i) for i in input().split()]
a.append(b)
maxim = 0
s = 0
d = 0
hash = []
a.sort(key=lambda v: v[0])
hash.append(a[0])
d += 1
maxim = a[0][1]
actual = maxim
for i in a[1:]:
while s < d:
if i[0] - hash[s][0] < dr:
break
actual -= hash[s][1]
s += 1
d += 1
hash.append(i)
actual += i[1]
maxim = max(maxim, actual)
print(maxim)
|
ASSIGN 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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
s = [0] * n
for _ in range(n):
m, f = map(int, input().split())
s[_] = m, f
s.sort()
i = 0
j = 0
ans = 0
fr = 0
while j < n:
if s[j][0] - s[i][0] < d:
fr += s[j][1]
j += 1
else:
ans = max(ans, fr)
while s[j][0] - s[i][0] >= d:
fr -= s[i][1]
i += 1
ans = max(ans, fr)
print(ans)
|
ASSIGN 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
inp = lambda: [*map(int, input().split())]
n, d = inp()
a = sorted([inp() for i in range(n)], key=lambda x: x[0])
b = [a[0][1]]
for i in range(1, n):
b.append(a[i][1] + b[i - 1])
b = [0] + b
p = q = 0
s = 0
ans = 0
while q < n:
while q < n and a[q][0] - a[p][0] < d:
q += 1
ans = max(ans, b[q] - b[p])
p += 1
print(ans)
|
ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
from sys import stdin, stdout
input = stdin.readline
n, h = map(int, input().split())
f = sorted([list(map(int, input().split())) for i in range(n)])
ans = 0
fc = f[0][1]
start = 0
for i in range(1, n):
while f[i][0] - f[start][0] >= h:
ans = max(ans, fc)
fc -= f[start][1]
start += 1
fc += f[i][1]
ans = max(ans, fc)
stdout.write(str(max(ans, fc)))
|
ASSIGN VAR VAR ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
mon = []
pre = [(0) for i in range(n)]
for i in range(n):
m, f = map(int, input().split())
mon.append((m, f))
mon.sort()
for i in range(n):
x, f = mon[i]
pre[i] = f
for i in range(1, n):
pre[i] += pre[i - 1]
pre.append(0)
j, i = 0, 0
ans = 0
su = 0
mx = 0
while i < n and j < n:
x, y = mon[i]
res, res2 = mon[j]
if res < x + d:
j += 1
else:
mx = max(mx, pre[j - 1] - pre[i - 1])
su = 0
i += 1
mx = max(mx, pre[j - 1] - pre[i - 1])
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, de = map(int, input().split())
d = {}
for i in range(n):
m, f = map(int, input().split())
d[m] = f if m not in d else d[m] + f
l = list(d.keys())
l.sort()
a = 0
maxf = 0
curf = 0
for b in range(len(l)):
if l[b] >= de + l[a]:
while 1:
if l[b] - l[a] < de:
break
else:
curf -= d[l[a]]
a += 1
curf += d[l[b]]
maxf = max(maxf, curf)
print(maxf)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR WHILE NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
[n, d] = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for i in range(n)]
a.sort(key=lambda a: a[0])
maxo = 0
i = 0
j = 0
k = 0
while j < n - 1:
while j <= n - 1 and a[i][0] + d > a[j][0]:
k += a[j][1]
j += 1
maxo = max(maxo, k)
k -= a[i][1]
i = i + 1
maxo = max(maxo, a[n - 1][1])
print(maxo)
|
ASSIGN LIST 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
n, d = f()
l = [list(f()) for _ in range(n)]
l.sort()
mx = 0
sm = 0
j = 0
for i in range(n):
while j < n and l[j][0] - l[i][0] < d:
sm += l[j][1]
j += 1
mx = max(mx, sm)
sm -= l[i][1]
print(mx)
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
from sys import stdin, stdout
lines = stdin.readlines()
n, d = int(lines[0].split()[0]), int(lines[0].split()[1])
mat = [[int(x.split()[0]), int(x.split()[1])] for x in lines[1:]]
mat = sorted(mat)
mx = 0
temp_mx = 0
i = 0
for j in range(n):
temp_mx += mat[j][1]
if mat[j][0] - mat[i][0] >= d:
while mat[j][0] - mat[i][0] >= d:
temp_mx -= mat[i][1]
i += 1
mx = max(temp_mx, mx)
print(mx)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
n, d = idata()
sp = []
for i in range(n):
sp += [idata()]
sp.sort()
l, r, maxx, ans = 0, 0, sp[0][1], sp[0][1]
while r != n - 1:
r += 1
maxx += sp[r][1]
while sp[r][0] - sp[l][0] >= d:
maxx -= sp[l][1]
l += 1
ans = max(ans, maxx)
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
a, b = map(int, input().split())
c = 0
f = 0
d = 0
e = list()
for _ in range(a):
g, h = map(int, input().split())
e.append([g, h])
e.sort()
for i in range(a):
c = c + e[i][1]
while e[i][0] - e[d][0] >= b:
c = c - e[d][1]
d = d + 1
f = max(f, c)
print(f)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
N, M = map(int, input().split())
values = []
for i in range(N):
m, f = input().split()
values.append((int(m), int(f)))
values.sort()
r = 0
l = 0
mx = 0
sum = 0
while r < N:
dif = values[r][0] - values[l][0]
if dif < M:
sum = sum + values[r][1]
mx = max(mx, sum)
r += 1
else:
sum -= values[l][1]
l += 1
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def find_company(friends, d):
def mergesort_tuples(tuples, index):
def merge(A, B):
i, j = 0, 0
result = []
while i < len(A) and j < len(B):
if A[i][index] < B[j][index]:
result.append(A[i])
i += 1
else:
result.append(B[j])
j += 1
result += A[i:]
result += B[j:]
return result
def divide(tuples):
if len(tuples) > 1:
middle = len(tuples) // 2
return merge(divide(tuples[:middle]), divide(tuples[middle:]))
return tuples
return divide(tuples)
def solve(friends, d):
friends = mergesort_tuples(friends, 0)
left_ptr = 0
right_ptr = 0
current_friendship = 0
max_friendship = 0
while right_ptr < len(friends):
if friends[right_ptr][0] - friends[left_ptr][0] < d:
current_friendship += friends[right_ptr][1]
right_ptr += 1
else:
max_friendship = max(current_friendship, max_friendship)
current_friendship -= friends[left_ptr][1]
left_ptr += 1
max_friendship = max(current_friendship, max_friendship)
return max_friendship
return solve(friends, d)
n, d = [int(x) for x in input().split()]
friends = []
for _ in range(n):
friends.append(tuple([int(x) for x in input().split()]))
print(find_company(friends, d))
|
FUNC_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
r = lambda: list(map(int, input().split()))
n, d = r()
a = sorted(tuple(r()) for i in range(n))
i = 0
Min = a[i][0]
Max = cur = 0
for m, s in a:
cur += s
if m - Min >= d:
while m - a[i][0] >= d:
cur -= a[i][1]
i += 1
Min = a[i][0]
Max = max(Max, cur)
print(Max)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
input = sys.stdin.readline
def check(num):
i, j = 0, 0
count = 0
while j < n:
while j < n and a[j][0] - a[i][0] < d:
count += a[j][1]
j += 1
if count >= num:
return True
count -= a[i][1]
i += 1
return False
n, d = map(int, input().split())
a = []
maxx = 0
for i in range(n):
a.append(list(map(int, input().split())))
maxx += a[-1][1]
a.sort()
if n == 1:
print(a[0][1])
exit()
low = 0
high = maxx
while low < high:
mid = (low + high) // 2
if check(mid):
low = mid + 1
else:
high = mid - 1
if check(low):
print(low)
else:
print(low - 1)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN 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 VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friend = [list(map(int, input().split())) for _ in range(n)]
friend.sort()
i, j, ans, window = 0, 0, 0, 0
while i < n:
if friend[i][0] - friend[j][0] < d:
window += friend[i][1]
ans = max(window, ans)
i += 1
else:
window -= friend[j][1]
j += 1
print(ans)
|
ASSIGN 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 ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def Kefa_and_Company():
n, dd = map(int, input().split())
d = {}
for i in range(n):
z, x = map(int, input().split())
d.setdefault(z, 0)
d[z] += x
m = list(d.keys())
m.sort()
f = [0]
for i in m:
f.append(f[-1] + d[i])
f.pop(0)
i = j = 0
ans = []
l = len(m)
while True:
if m[j] - m[i] >= dd:
if i == 0:
ans.append(f[j - 1])
else:
ans.append(f[j - 1] - f[i - 1])
i += 1
else:
if j == l - 1:
if i == 0:
ans.append(f[j])
elif i == l - 1:
ans.append(f[j] - f[i - 1])
else:
ans.append(f[j] - f[i - 1])
break
j += 1
ws = max(ans)
print(ws)
return
Kefa_and_Company()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER IF BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def cmp(t):
return t[0]
n, d = (int(i) for i in input().split())
lista = []
for i in range(n):
a, b = (int(i) for i in input().split())
lista.append((a, b))
lista.sort(key=cmp)
maxim = 0
j = 0
crt = 0
for i in range(len(lista)):
while j < len(lista) and lista[j][0] - lista[i][0] < d:
crt = crt + lista[j][1]
j += 1
if maxim < crt:
maxim = crt
crt = crt - lista[i][1]
print(maxim)
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def key_tri(argument):
return argument[0]
n, d = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(n)]
L.sort(key=key_tri)
deb = 0
T = []
s = 0
for k in range(1, n):
if L[k][0] - L[deb][0] >= d:
s = 0
for i in range(deb, k):
s += L[i][1]
T += [s]
s = deb + 1
while L[k][0] - L[s][0] >= d:
s += 1
deb = s
s = 0
for k in range(deb, n):
s += L[k][1]
T = T + [s]
print(max(T))
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR LIST VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
arr = []
xx = 0
for i in range(n):
m, fr = map(int, input().split())
xx += m
arr.append([m, fr, xx])
arr = sorted(arr)
cc = 0
ans = 0
r = 0
for i in range(len(arr)):
while r < len(arr) and arr[r][0] - arr[i][0] < d:
cc += arr[r][1]
r += 1
ans = max(ans, cc)
cc -= arr[i][1]
print(ans)
|
ASSIGN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def bina(arr, target, i, n):
l, h, ans = i, n - 1, i
while l <= h:
m = (l + h) // 2
if arr[m][0] >= target:
h = m - 1
else:
ans = m
l = m + 1
return ans
n, d = list(map(int, input().split()))
arr = [tuple(map(int, input().split())) for _ in range(n)]
arr.sort(key=lambda x: x[0])
prefix = [0] * n
prefix[0] = arr[0][1]
for i in range(1, n):
prefix[i] = prefix[i - 1] + arr[i][1]
mx = -1
for i in range(n):
target = arr[i][0] + d
ind = bina(arr, target, i, n)
mx = max(mx, prefix[ind] - prefix[i] + arr[i][1])
print(mx)
|
FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def solve():
rd = lambda: list(map(int, input().split()))
n, d = rd()
arr = []
for i in range(n):
a, b = rd()
arr.append((a, b))
arr.sort()
prev = -1
val = -1
tmp = -1
for i, t in enumerate(arr):
a, b = t
if prev == -1:
val = b
prev = i
elif a - arr[prev][0] < d:
val += b
else:
tmp = max(val, tmp)
while a - arr[prev][0] >= d:
val -= arr[prev][1]
prev += 1
val += b
print(max(tmp, val))
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
a = []
for i in range(n):
a.append([int(i) for i in input().split()])
a.sort()
money = 0
f = a[0][1]
ff = []
for i in range(1, n):
if a[i][0] < a[money][0] + d:
f += a[i][1]
else:
ff.append(f)
while a[i][0] >= a[money][0] + d:
f -= a[money][1]
money += 1
f += a[i][1]
ff.append(f)
print(max(ff))
|
ASSIGN 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = [int(i) for i in input().split()]
friends = []
for i in range(n):
lista = []
m, s = [int(i) for i in input().split()]
lista = [m, s]
friends.append(lista)
friends_ordenados = sorted(friends)
soma_factors = []
inicio, fim, soma = 0, 0, 0
while fim < n:
if friends_ordenados[fim][0] - friends_ordenados[inicio][0] < d:
soma += friends_ordenados[fim][1]
fim += 1
else:
soma_factors.append(soma)
soma -= friends_ordenados[inicio][1]
inicio += 1
soma_factors.append(soma)
print(max(soma_factors))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = input().split()
n, d = int(n), int(d)
a = []
for i in range(n):
x = input().split()
x[0], x[1] = int(x[0]), int(x[1])
a.append(x)
def cmp(x):
return x[0]
a = sorted(a, key=cmp)
ans, acc, rptr = 0, 0, -1
for i in range(n):
while rptr < n - 1 and a[rptr + 1][0] < a[i][0] + d:
rptr, acc = rptr + 1, acc + a[rptr + 1][1]
ans = max(ans, acc)
acc -= a[i][1]
print(ans)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
user = input().split(" ")
numberFriends = int(user[0])
diffToFeelPoor = int(user[1])
arr = []
maxFac = -1
for _ in range(numberFriends):
userIn = input().split(" ")
money = int(userIn[0])
frFac = int(userIn[1])
if frFac > maxFac:
maxFac = frFac
arr.append((money, frFac))
if diffToFeelPoor > 0:
arr.sort(key=lambda tup: tup[0])
currFac = arr[0][1]
maxFac = arr[0][1]
startIn = 0
index = 1
while index < len(arr):
if arr[index][0] < arr[startIn][0] + diffToFeelPoor:
currFac += arr[index][1]
if currFac > maxFac:
maxFac = currFac
else:
currFac += arr[index][1]
for index2 in range(startIn, index + 1):
if arr[index][0] >= arr[index2][0] + diffToFeelPoor:
currFac -= arr[index2][1]
startIn = index2 + 1
else:
break
if currFac > maxFac:
maxFac = currFac
index += 1
if currFac > maxFac:
maxFac = currFac
print(maxFac)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
class Guest(object):
def __init__(self, money, friendship_factor):
self.money = money
self.friendship_factor = friendship_factor
def __repr__(self):
return "Guest"
def __str__(self):
return " ".join(["Guest:", str(self.money), str(self.friendship_factor)])
class Company(object):
def __init__(self, number_of_guests, poorness_threshold):
self.number_of_guests = number_of_guests
self.poorness_threshold = poorness_threshold
self.list_of_guests = list()
self.maximum_sum_of_friendship = 0
def add_guest(self, money, friendship_factor):
self.list_of_guests.append(Guest(money, friendship_factor))
def sort_guest_list(self):
self.list_of_guests.sort(key=lambda guest: guest.money)
def compute_maximal_friendship(self):
temporary_friendship = 0
trailing_guest_index = 0
for guest_index in range(self.number_of_guests):
temporary_friendship += self.list_of_guests[guest_index].friendship_factor
while (
self.list_of_guests[guest_index].money
- self.list_of_guests[trailing_guest_index].money
>= self.poorness_threshold
):
temporary_friendship -= self.list_of_guests[
trailing_guest_index
].friendship_factor
trailing_guest_index += 1
if self.maximum_sum_of_friendship < temporary_friendship:
self.maximum_sum_of_friendship = temporary_friendship
input_number_of_guests, input_poorness_threshold = map(int, input().split(" "))
company = Company(input_number_of_guests, input_poorness_threshold)
for counter in range(input_number_of_guests):
input_money, input_friendship_factor = map(int, input().split(" "))
company.add_guest(input_money, input_friendship_factor)
company.sort_guest_list()
company.compute_maximal_friendship()
print(company.maximum_sum_of_friendship)
|
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN STRING FUNC_DEF RETURN FUNC_CALL STRING LIST STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = list(map(int, input().split()))
res = []
for i in range(n):
res.append(list(map(int, input().split())))
res.sort()
res.reverse()
res.append([0, 0])
left = 0
right = 0
summ = 0
rsumm = 0
while True:
while res[left][0] - d < res[right][0]:
summ += res[right][1]
right += 1
if right == n + 1:
break
if right == n + 1:
break
rsumm = max(summ, rsumm)
summ -= res[left][1]
left += 1
rsumm = max(summ, rsumm)
print(rsumm)
|
ASSIGN VAR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = []
s, ans, ind = 0, 0, 0
for i in range(n):
friends.append(list(map(int, input().split())))
friends.sort(key=lambda numb: numb[0])
for j in range(n):
s += friends[j][1]
while friends[j][0] - friends[ind][0] >= d:
s -= friends[ind][1]
ind += 1
ans = max(ans, s)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append([x, y])
a.sort()
partialsum = [0] * n
partialsum[0] = a[0][1]
for i in range(1, n):
partialsum[i] = partialsum[i - 1] + a[i][1]
mx = partialsum[0]
cnt = 0
for i in range(1, n):
while cnt < i and a[i][0] - a[cnt][0] >= d:
cnt += 1
if cnt > 0:
mx = max(mx, partialsum[i] - partialsum[cnt - 1])
else:
mx = max(mx, partialsum[i])
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
line = input()
n, d = map(int, line.split())
ms = []
for i in range(n):
line = input()
tmp = list(map(int, line.split()))
ms.append(tmp)
ms = sorted(ms, key=lambda ms: ms[0])
i = 0
j = 0
ans = 0
while j < n and abs(ms[i][0] - ms[j][0]) < d:
ans += ms[j][1]
j += 1
maxx = ans
while j < n:
ans += ms[j][1]
while abs(ms[i][0] - ms[j][0]) >= d:
ans -= ms[i][1]
i += 1
if maxx < ans:
maxx = ans
j += 1
print(maxx)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
I = lambda: map(int, input().split())
n, d = I()
a = sorted([list(I()) for i in range(n)])
s = ans = a[0][1]
j = 0
for i in range(1, n):
while a[i][0] - a[j][0] >= d:
s -= a[j][1]
j += 1
s += a[i][1]
ans = max(s, ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def CMP(x):
return x[0]
def b_search(l, r, x):
ans = l
while l <= r:
mid = (l + r) // 2
if a[mid][0] <= x:
ans = mid
l = mid + 1
else:
r = mid - 1
return ans
s = input().split()
n, d = int(s[0]), int(s[1])
a = []
for i in range(n):
s = input().split()
a.append([int(s[0]), int(s[1])])
a.sort(key=CMP)
s = [(0) for x in range(n)]
s[0] = a[0][1]
for i in range(1, n):
s[i] = s[i - 1] + a[i][1]
ans = 0
for i in range(n):
j = b_search(i, n - 1, a[i][0] + d - 1)
if i == 0:
ans = s[j]
else:
ans = max(ans, s[j] - s[i - 1])
print(ans)
|
FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = [int(x) for x in input().split()]
li = []
for i in range(n):
l = list(map(int, input().split()))
li.append(l)
li.sort()
lii = []
b = 0
for i in range(n):
if i == 0:
num = 0
else:
num = num - li[i - 1][1]
a = 0
for j in range(b, n):
if li[j][0] < li[i][0] + d:
num += li[j][1]
else:
a = 1
b = j
break
if a == 0:
b = n
lii.append(num)
print(max(lii))
|
ASSIGN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = []
for i in range(n):
money, factor = map(int, input().split())
friends.append([money, factor])
friends.sort()
ans = 0
tmp_ans = friends[0][1]
back = 0
front = 1
while front < n:
if friends[front][0] - friends[back][0] < d:
tmp_ans += friends[front][1]
front += 1
else:
if tmp_ans > ans:
ans = tmp_ans
while friends[front][0] - friends[back][0] >= d:
tmp_ans -= friends[back][1]
back += 1
if back == front:
tmp_ans += friends[back][1]
front += 1
if tmp_ans > ans:
ans = tmp_ans
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
a, d = map(int, input().split())
ans = []
for i in range(a):
z = list(map(int, input().split()))
ans.append(z)
ans.sort(key=lambda x: (x[0], x[1]))
l = 0
r = 0
maxa = []
mi = 0
i = 0
while l <= r and r < len(ans):
if ans[r][0] - ans[l][0] < d:
mi += ans[i][1]
r += 1
i += 1
else:
maxa.append(mi)
l += 1
mi = maxa[-1] - ans[l - 1][1]
maxa.append(mi)
print(max(maxa))
|
ASSIGN 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 EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = [int(x) for x in input().split()]
dict = {}
for i in range(n):
m, s = [int(x) for x in input().split()]
if dict.get(m) == None:
dict[m] = s
else:
dict[m] += s
sortedKeys = sorted(dict.keys())
leng = len(sortedKeys)
s = 0
r = 0
while r < leng:
if sortedKeys[r] < sortedKeys[0] + d:
s += dict.get(sortedKeys[r])
r += 1
else:
break
maxValue = s
for i in range(1, leng):
l = i - 1
s -= dict.get(sortedKeys[l])
while r < leng and sortedKeys[i] + d > sortedKeys[r]:
s += dict.get(sortedKeys[r])
r += 1
maxValue = max(maxValue, s)
if r == leng:
break
print(maxValue)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
from sys import stdin
live = True
if not live:
stdin = open("data.in", "r")
n, limit = list(map(int, stdin.readline().strip().split()))
friends = []
for i in range(n):
m, s = list(map(int, stdin.readline().strip().split()))
friends += [(m, s)]
friends = sorted(friends, key=lambda t: t[0])
ans = temp = friends[0][1]
start = 0
for i, j in friends[1:]:
if temp > ans:
ans = temp
temp += j
while not i - friends[start][0] < limit:
temp -= friends[start][1]
start += 1
if temp > ans:
ans = temp
print(ans)
if not live:
stdin.close()
|
ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR 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 VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = []
for i in range(n):
friends.append(tuple(map(int, input().split())))
friends.sort(key=lambda x: x[0])
prefix = [0] * n
prefix[0] = friends[0][1]
for i in range(1, n):
prefix[i] += prefix[i - 1]
le = 0
r = 0
curr_sum = 0
ans = max(f[1] for f in friends)
while le < n:
while r < n and abs(friends[r][0] - friends[le][0]) < d:
curr_sum += friends[r][1]
r += 1
ans = max(ans, curr_sum)
curr_sum -= friends[le][1]
le += 1
print(ans)
|
ASSIGN 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 EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR WHILE VAR VAR WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def solve(n, d, friends):
big = float("inf")
small = float("-inf")
friends.sort()
maxer = small
f = 0
s = 0
ind = 0
curr = 0
while ind < n:
last = 0
miner = friends[s][0]
while s < n and abs(friends[ind][0] - friends[s][0]) >= d:
curr -= friends[s][1]
s += 1
miner = friends[s][0]
flag = True
while ind < n and abs(friends[ind][0] - miner) < d:
curr += friends[ind][1]
ind += 1
flag = False
if flag:
curr += friends[ind][1] + last
ind += 1
maxer = max(maxer, curr - last)
return maxer
def main():
d = input()
d = [int(i) for i in d.split()]
a = d[0]
b = d[1]
friends = []
for i in range(a):
d = input()
d = [int(i) for i in d.split()]
m = d[0]
f = d[1]
friends.append((m, f))
ans = solve(a, b, friends)
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
a = []
for i in range(n):
x = list(map(int, input().split()))
a.append(x)
a.sort()
i = 0
j = 1
ans = a[0][1]
md = a[0][0] + d
ansq = ans
while j != n:
if a[j][0] < md:
ans += a[j][1]
ansq = max(ans, ansq)
j += 1
else:
ans -= a[i][1]
ansq = max(ans, ansq)
i += 1
md = a[i][0] + d
print(ansq)
|
ASSIGN 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def main():
n, d = [int(x) for x in input().split()]
preffac = [0]
friends = []
for i in range(n):
m, s = [int(x) for x in input().split()]
friends.append((m, s))
friends.sort()
kon = -1
wyn = 0
ob = 0
for pocz in range(n):
if kon < pocz:
kon = pocz
ob = friends[pocz][1]
while kon + 1 < n and friends[kon + 1][0] - friends[pocz][0] < d:
ob += friends[kon + 1][1]
kon += 1
wyn = max(wyn, ob)
ob -= friends[pocz][1]
print(wyn)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
R = lambda: list(map(int, input().split()))
n, m = R()
x = range(n)
c = 0
d = 0
l = 0
r = 0
f = sorted([R() for i in range(n)])
while n > l:
while n > r and f[r][0] - f[l][0] < m:
c += f[r][1]
r += 1
d = max(d, c)
c -= f[l][1]
l += 1
print(d)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = list(map(int, input().split()))
li = []
for i in range(n):
m, s = list(map(int, input().split()))
li.append([m, s])
li.sort()
r = 0
c = 0
j = 0
for i in li:
c += i[1]
while i[0] - li[j][0] >= d:
c -= li[j][1]
j += 1
r = max(r, c)
print(r)
|
ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def readnums():
return list(map(lambda x: int(x), input().split(" ")))
n, d = readnums()
fr = []
for i in range(n):
fr.append(tuple(readnums()))
fr.sort()
ans = 0
min_money = 0
friendship = 0
i = 0
j = 0
while i < n:
min_money = fr[i][0]
ans = max(ans, friendship)
if i > j:
j = i
while j < n and abs(fr[j][0] - min_money) < d:
friendship += fr[j][1]
j += 1
ans = max(ans, friendship)
friendship -= fr[i][1]
i += 1
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = list(map(int, input().split()))
m = []
s = []
for _ in range(n):
m_, s_ = list(map(int, input().split()))
m.append(m_)
s.append(s_)
data = sorted(zip(m, s), key=lambda x: x[0])
m = [d[0] for d in data]
s = [d[1] for d in data]
j = 0
i = 0
mx = s[i]
res = []
while i < n:
res.append(mx)
if j + 1 < n and m[j + 1] - m[i] < d:
j += 1
mx += s[j]
elif i == j and i + 1 < n:
i += 1
j += 1
mx = s[i]
else:
mx -= s[i]
i += 1
print(max(res))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
class Solution:
def max_friendship_factor(self, money_diff, friends_data):
friends_data = sorted(friends_data, key=lambda f: f[0])
factors = [friends_data[0][1]]
for i in range(1, len(friends_data)):
factors.append(factors[i - 1] + friends_data[i][1])
ff_max, j = 0, len(friends_data) - 1
for i in range(len(friends_data) - 1, -1, -1):
while j > 0 and friends_data[j][0] - friends_data[i][0] >= money_diff:
j -= 1
ff = factors[j]
if i > 0:
ff -= factors[i - 1]
if ff > ff_max:
ff_max = ff
return ff_max
def main():
inp = sys.stdin.readline()
friends, money_diff = list(map(int, inp.split()))
friends_data = []
while friends > 0:
inp = sys.stdin.readline()
friends_data.append(list(map(int, inp.split())))
friends -= 1
print(Solution().max_friendship_factor(money_diff, friends_data))
main()
|
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
ans = [list(map(int, input().split())) for _ in range(n)]
ans.sort(key=lambda x: x[0])
maxi = -199999
st = 0
end = 0
sm1 = 0
sm = 0
start = 0
while end < n:
sm += ans[end][1]
sm1 = ans[end][0]
while st <= end and sm1 - ans[st][0] >= d:
sm -= ans[st][1]
st += 1
maxi = max(maxi, sm)
end += 1
print(maxi)
|
ASSIGN 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
a, b = map(int, input().split())
x = [[0, 0]]
mx = 0
c1 = 1
c2 = 1
for i in range(a):
x.append(list(map(int, input().split())))
x.sort()
for i in range(1, a + 1):
x[i][1] = x[i - 1][1] + x[i][1]
for c1 in range(0, a + 1):
c2 = max(c1, c2)
while c2 < a + 1 and x[c2][0] < x[c1][0] + b:
c2 += 1
mx = max(mx, x[c2 - 1][1] - x[c1 - 1][1])
if mx == 19:
print(c2, c1)
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
inf = float("inf")
mod = 1000000007
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline()
def main():
n, d = get_ints()
arr = [0] * n
for i in range(n):
arr[i] = get_array()
arr.sort()
ans = 0
j = 0
curr = 0
for i in range(n):
while j < n and arr[j][0] < arr[i][0] + d:
curr += arr[j][1]
j += 1
ans = max(ans, curr)
curr -= arr[i][1]
print(ans)
main()
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
[n, d] = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
ans = a[0][1]
res = a[0][1]
p1 = 0
p2 = 0
while p2 < n - 1:
if a[p2 + 1][0] - a[p1][0] < d:
p2 += 1
ans += a[p2][1]
if ans > res:
res = ans
else:
ans -= a[p1][1]
p1 += 1
print(res)
|
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def getIndex(a, k, start, end, val, i):
if start == end:
if val - a[start][0] < k:
return start
return i
mid = (start + end) // 2
if val - a[mid][0] < k:
return getIndex(a, k, start, mid, val, i)
return getIndex(a, k, mid + 1, end, val, i)
n, k = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
a.sort(key=lambda x: x[0])
pref = [(0) for i in range(n)]
glob = a[0][1]
pref[0] = a[0][1]
for i in range(1, n):
pref[i] = pref[i - 1] + a[i][1]
for i in range(1, n):
temp = getIndex(a, k, 0, i - 1, a[i][0], i)
glob = max(glob, pref[i] - (pref[temp - 1] if temp - 1 >= 0 else 0))
print(glob)
|
FUNC_DEF IF VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR RETURN VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN 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 EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
class Friend:
def __init__(self, m, s):
self.m = m
self.s = s
n, d = list(map(int, input().split()))
friends = []
for i in range(n):
m, s = list(map(int, input().split()))
friends.append(Friend(m, s))
friends.sort(key=lambda f: f.m)
max_score = 0
right = 0
curr = 0
for left in range(n):
while right < n and friends[right].m < d + friends[left].m:
curr += friends[right].s
right += 1
max_score = max(max_score, curr)
curr -= friends[left].s
print(max_score)
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = []
for i in range(n):
m, f = map(int, input().split())
friends.append([m, f])
friends.sort(key=lambda x: x[0])
l, r, s = 0, 0, friends[0][1]
sums = []
for i in range(1, n):
r += 1
if friends[r][0] - friends[l][0] < d:
s += friends[i][1]
else:
sums.append(s)
while friends[r][0] - friends[l][0] >= d:
s -= friends[l][1]
l += 1
s += friends[r][1]
sums.append(s)
print(max(sums))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
m = [tuple(map(int, input().split())) for _ in range(n)]
m = sorted(m)
f = 0
fr = m[f][1]
poss = []
for i in range(1, n):
if m[i][0] - m[f][0] < d:
fr += m[i][1]
else:
poss.append(fr)
fr -= m[f][1]
f += 1
while f < i:
if m[i][0] - m[f][0] < d:
break
fr -= m[f][1]
f += 1
fr += m[i][1]
poss.append(fr)
print(max(poss))
|
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def lb(l, r, a, k):
while l < r:
m = (l + r) // 2
if a[m] < k:
l = m + 1
else:
r = m
return l
def ub(l, r, a, k):
while l < r:
m = (l + r) // 2
if a[m] <= k:
l = m + 1
else:
r = m
return l
def part(a, b, v):
if a - 1 < 0:
return v[b][1]
return v[b][1] - v[a - 1][1]
n, m = input().split()
arr = list()
ll = list()
for i in range(int(n)):
a, b = input().split()
arr.append((int(a), int(b)))
ll.append(int(a))
arr.sort()
ll.sort()
for i in range(1, len(arr)):
arr[i] = arr[i][0], arr[i][1] + arr[i - 1][1]
rpta = 0
cnt = 0
for i in ll:
f = lb(0, int(n), ll, i - int(m) + 1)
rpta = max(rpta, part(f, cnt, arr))
cnt = cnt + 1
print(rpta)
|
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR VAR NUMBER RETURN BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def binarySearch(alist, value):
first = 0
last = len(alist) - 1
while first <= last:
midpoint = (first + last) // 2
if value >= alist[midpoint]["m"] and value < alist[midpoint + 1]["m"]:
return midpoint
elif value >= alist[midpoint + 1]["m"]:
first = midpoint + 1
elif value < alist[midpoint]["m"]:
last = midpoint - 1
return 10**10
[n, d] = list(map(int, input().split(" ")))
a = []
for i in range(n):
[m, s] = list(map(int, input().split(" ")))
a.append({"m": m, "s": s})
a.sort(key=lambda x: x["m"])
a.append({"m": 10**10, "s": 0})
t = [a[0]["s"]]
for i in range(1, n + 1):
t.append(t[i - 1] + a[i]["s"])
m = 0
for i in range(n):
v = a[i]["m"] + d - 1
e = binarySearch(a, v)
r = t[e] - (0 if i == 0 else t[i - 1])
m = max(m, r)
print(m)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING RETURN VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR DICT STRING STRING VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR DICT STRING STRING BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def main(n, d):
p = []
for i in range(n):
a, b = list(map(int, input().split()))
p.append([a, b])
p.sort()
maxi = 0
sum = 0
e = []
g = 0
em = 0
while len(p) != 0:
while g != n and p[g][0] < p[em][0] + d:
sum += p[g][1]
g += 1
if g == n:
maxi = max(maxi, sum)
print(max(maxi, sum))
break
else:
maxi = max(maxi, sum)
while em != g and p[em][0] + d <= p[g][0]:
sum -= p[em][1]
em += 1
n, d = list(map(int, input().split()))
main(n, d)
|
FUNC_DEF ASSIGN VAR LIST 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 LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
friends = []
n, d = map(int, input().split())
for i in range(n):
friends.append(tuple(map(int, input().split())))
friends.sort()
sums = [friends[0][1]]
for i in range(1, n):
sums.append(sums[i - 1] + friends[i][1])
l = r = 0
answer = 0
while l <= n - 1 and r <= n - 1:
if friends[r][0] - friends[l][0] < d:
if sums[r] - sums[l] + friends[l][1] > answer:
answer = sums[r] - sums[l] + friends[l][1]
r += 1
elif l <= r - 1:
l += 1
else:
r += 1
print(answer)
|
ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
user_input = input()
first_line = user_input.split(" ")
n = int(first_line[0])
d = int(first_line[1])
long_list = []
for i in range(n):
extended_list = []
user_input = input()
line = user_input.split(" ")
extended_list.extend([int(line[0]), int(line[1])])
long_list.append(extended_list)
long_list.sort()
index = 0
maximum = 0
for i in range(len(long_list)):
if maximum < long_list[i][1]:
maximum = long_list[i][1]
answer = maximum
maximum = 0
i = 0
count = 0
looped = "false"
while i in range(len(long_list)):
if long_list[i][0] - long_list[index][0] > d:
if count > 0 and looped == "false":
i -= count
count = 0
index = i
looped = "true"
else:
index = i
maximum = 0
if long_list[i][0] - long_list[index][0] < d:
count += 1
if maximum == 0:
maximum = long_list[index][1]
else:
maximum += long_list[i][1]
answer = max(answer, maximum)
i += 1
print(answer)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR NUMBER VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
class Dupla:
def __init__(self, money, factor):
self.money = money
self.factor = factor
def getMoney(self):
return self.money
def getFactor(self):
return self.factor
def __repr__(self):
return " - ".join(map(str, (self.money, self.factor)))
def __lt__(self, other):
return self.money < other.money
a = []
n, d = map(int, input().split())
for i in range(n):
m, f = map(int, input().split())
t = Dupla(m, f)
a.append(t)
s = sorted(a)
maxi1 = s[0].getFactor()
maxi2 = s[0].getFactor()
i = 1
j = 0
while i < n:
if abs(s[j].getMoney() - s[i].getMoney()) < d:
maxi1 += s[i].getFactor()
i += 1
if maxi1 > maxi2:
maxi2 = maxi1
else:
maxi1 -= s[j].getFactor()
j += 1
print(maxi2)
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR FUNC_DEF RETURN VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
money = []
factor = []
for i in range(n):
m, s = map(int, input().split())
money.append(m)
factor.append(s)
factor = [x for _, x in sorted(zip(money, factor))]
money = sorted(money)
i = j = 0
ans = 0
c = 0
while i < n and j < n:
if money[j] - money[i] < d:
c += factor[j]
j += 1
else:
c -= factor[i]
i += 1
ans = max(c, ans)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
l = sorted([tuple(map(int, input().split())) for i in range(n)])
po = ki = ma = 0
su = l[po][1]
for i in range(n):
while l[po][0] <= l[i][0] - d:
su -= l[po][1]
po += 1
while ki < n - 1 and l[ki + 1][0] < l[po][0] + d:
ki += 1
su += l[ki][1]
if su > ma:
ma = su
print(ma)
|
ASSIGN 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 ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
li = []
for i in range(n):
li.append(list(map(int, input().split())))
li = sorted(li)
su = [0] * n
su[0] = li[0][1]
for i in range(1, n):
su[i] = su[i - 1] + li[i][1]
li = [x[0] for x in li]
po = 0
ma = 0
for i in range(n):
while po < n - 1 and li[po + 1] - li[i] < d:
po = po + 1
if i == 0:
ma = max(ma, su[po])
else:
ma = max(ma, su[po] - su[i - 1])
print(ma)
|
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = [[] for i in range(n)]
for i in range(n):
m, s = map(int, input().split())
friends[i] = [m, s]
friends.sort()
li = [0] * n
i, j = 0, 0
tot = 0
while i < n:
currI = friends[i]
tot += currI[1]
while currI[0] - friends[j][0] >= d:
tot -= friends[j][1]
j += 1
li[i] = tot
i += 1
print(max(li))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n = input().split(" ")
n, d = int(n[0]), int(n[1])
a = [0] * n
for i in range(n):
m = input().split(" ")
a[i] = [int(m[0]), int(m[1])]
a.sort()
maxD = 0
count = a[0][1]
i, j = 0, 1
while j < n:
if a[j][0] - a[i][0] < d:
count += a[j][1]
j += 1
else:
maxD = max(count, maxD)
count -= a[i][1]
i += 1
print(max(count, maxD))
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
x = []
for i in range(n):
a, b = map(int, input().split())
x.append((a, b))
x.sort()
y = []
s = x[0][1]
i, j = 0, 1
while i < n and j < n:
if j < n and x[j][0] - x[i][0] < d:
s += x[j][1]
j += 1
else:
y.append(s)
s -= x[i][1]
i += 1
y.append(s)
print(max(y))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = input().split()
n = int(n)
d = int(d)
list1 = []
j = 0
for i in range(n):
list1.append([int(a) for a in input().split()])
list1.sort()
list2 = []
m1 = summ = j = 0
for i in range(len(list1)):
summ += list1[i][1]
while list1[i][0] - list1[j][0] >= d:
summ -= list1[j][1]
j += 1
m1 = max(summ, m1)
print(m1)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
input = sys.stdin.readline
prnt = sys.stdout.write
n, d = map(int, input().split())
ls = []
for i in range(n):
m, f = map(int, input().split())
ls.append([m, f])
ls.sort()
mx = ls[0][1]
res = ls[0][1]
j = 0
for i in range(1, n):
if ls[i][0] - ls[j][0] >= d:
res = max(mx, res)
while ls[i][0] - ls[j][0] >= d:
j += 1
mx = 0
for x in range(j, i + 1):
mx += ls[x][1]
else:
mx += ls[i][1]
res = max(mx, res)
prnt(str(res))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
from sys import stdin, stdout
lines = stdin.readlines()
n, d = int(lines[0].split()[0]), int(lines[0].split()[1])
a = sorted([[int(x.split()[0]), int(x.split()[1])] for x in lines[1:]])
max_val = 0
start_pointer = 0
cur_val = 0
for end_pointer in range(n):
cur_val += a[end_pointer][1]
while a[end_pointer][0] - a[start_pointer][0] >= d:
cur_val -= a[start_pointer][1]
start_pointer += 1
if cur_val > max_val:
max_val = cur_val
print(max_val)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
n, d = map(int, sys.stdin.readline().split())
f = dict()
for _ in range(n):
m, s = map(int, sys.stdin.readline().split())
if m in f:
f[m] += s
else:
f[m] = s
fkey = sorted(f.keys())
fkey_min = fkey[0]
fkey_max = fkey[-1]
fkey_tmp = []
for i in fkey:
if i <= min(fkey_min + d - 1, fkey_max):
fkey_tmp.append(i)
ans = sum([f[i] for i in fkey_tmp])
tmp = ans
for i in range(len(fkey_tmp), len(fkey)):
fkey_tmp.append(fkey[i])
tmp += f[fkey_tmp[-1]]
while fkey_tmp[0] <= fkey_tmp[-1] - d:
tmp -= f[fkey_tmp[0]]
fkey_tmp.pop(0)
ans = max(ans, tmp)
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = [int(i) for i in input().split()]
dr = []
for i in range(n):
dr.append([int(i) for i in input().split()])
dr.sort()
fri = []
l = 0
r = 1
fr = 0
go = dr[0][1]
for l in range(n):
fr = dr[l][0]
while r < n and dr[r][0] - fr < d:
go += dr[r][1]
r += 1
fri.append(go)
go -= dr[l][1]
print(max(fri))
|
ASSIGN 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
__author__ = "User"
def p(x):
l = 0
r = n
while l + 1 < r:
m = (l + r) // 2
if arr[m][0] <= x:
l = m
else:
r = m
return l
def p2(x):
l = -1
r = n - 1
while l + 1 < r:
m = (l + r) // 2
if arr[m][0] < x:
l = m
else:
r = m
return r
n, d = map(int, input().split())
arr = [0] * n
summ = [0] * n
s = 0
for i in range(n):
arr[i] = tuple(map(int, input().split()))
arr.sort()
for i in range(n):
summ[i] = s + arr[i][1]
s += arr[i][1]
summ.append(0)
mx = 0
c = 0
for i in arr:
r = p(i[0] + (d - 1))
l = p2(i[0])
s = summ[r] - summ[l - 1]
mx = max(mx, s)
print(mx)
|
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = input().split()
L = []
for i in range(int(n) + 1):
if i == 0:
L.append([0, 0])
else:
m, f = input().split()
L.append([int(m), int(f)])
L.sort(key=lambda X: X[0])
Sum = 0
for i in range(1, int(n) + 1):
Sum += L[i][1]
L[i][1] = Sum
j = dif = 0
answer = 0
for i in range(1, int(n) + 1):
if L[i][0] - L[j][0] < int(d):
dif = L[i][0] - L[j][0]
else:
dif = L[i][0] - L[j][0]
while dif >= int(d):
j += 1
dif = L[i][0] - L[j][0]
if j == 0:
answer = max(answer, L[i][1] - L[j][1])
else:
answer = max(answer, L[i][1] - L[j - 1][1])
print(answer)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append((x, y))
a.sort()
sum1 = 0
m = 0
j = 0
for i in range(n):
while a[i][0] - a[j][0] >= d:
sum1 = sum1 - a[j][1]
j = j + 1
sum1 = sum1 + a[i][1]
m = max(m, sum1)
print(m)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def sortFirst(val):
return val[0]
friends, d = input().split()
friends = int(friends)
d = int(d)
money = []
for i in range(friends):
mon, fact = input().split()
mon = int(mon)
fact = int(fact)
money.append((mon, fact))
money.sort(key=sortFirst)
ini = 0
i = ini
maxp1 = 0
maximum = 0
while i <= friends - 1:
if money[ini][0] + d > money[i][0]:
maxp1 += money[i][1]
i += 1
else:
maximum = max(maximum, maxp1)
maxp1 -= money[ini][1]
ini += 1
total = max(maximum, maxp1)
print(total)
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def kac(l, d):
l.sort(reverse=True)
ma = l[0][1]
v = l[0][1]
i = j = 0
for i in range(1, len(l)):
v = v + l[i][1]
while abs(l[i][0] - l[j][0]) >= d:
v -= l[j][1]
j += 1
if v > ma:
ma = v
print(ma)
return
n, d = map(int, input().split())
l1 = []
for i in range(n):
m = list(map(int, input().split()))
l1.append(m)
kac(l1, d)
|
FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN 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 EXPR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = list(map(int, input().rstrip().split()))
li = []
for i in range(n):
li += [list(map(int, input().rstrip().split()))]
li.sort(key=lambda x: x[0])
j = 0
f = 0
ans = li[0][1]
i = 0
while i < n:
while li[i][0] - li[j][0] >= d:
f -= li[j][1]
j += 1
f += li[i][1]
ans = max(ans, f)
i += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
l = list(map(int, input().rstrip().split()))
a = []
for i in range(l[0]):
k = list(map(int, input().rstrip().split()))
a.append(k)
a.sort()
end = 0
strat = 0
trust = 0
subtrust = 0
k = 0
while end < len(a):
if abs(a[strat][0] - a[end][0]) < l[1]:
subtrust += a[end][1]
end += 1
trust = max(trust, subtrust)
else:
subtrust -= a[strat][1]
strat += 1
print(trust)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
vals = []
for i in range(n):
m, s = map(int, input().split())
vals.append((m, s))
vals.sort()
maxVal = vals[0][1]
position = 1
totals = vals[0][1]
for m, s in vals:
while position < len(vals) and vals[position][0] < m + d:
totals += vals[position][1]
position += 1
if totals > maxVal:
maxVal = totals
totals -= s
print(maxVal)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
arr = []
for i in range(n):
temp = list(map(int, input().split()))
arr.append(temp)
arr = sorted(arr)
fri_factor = 0
mx_fri_factor = 0
money_min = arr[0][0]
l = 0
r = 0
while l <= n - 1:
while l <= r and r < n:
if arr[r][0] - arr[l][0] < d:
fri_factor += arr[r][1]
r += 1
else:
break
mx_fri_factor = max(mx_fri_factor, fri_factor)
fri_factor -= arr[l][1]
l += 1
print(mx_fri_factor)
|
ASSIGN 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
a = []
for i in range(n):
l = input().split()
a.append(int(l[0]) * (10**9 + 1) + int(l[1]))
a.sort()
b = []
c = []
x = a[0] % (10**9 + 1)
y = a[0] // (10**9 + 1)
b.append([y, x])
for i in range(1, n):
x = a[i] % (10**9 + 1)
y = a[i] // (10**9 + 1)
b.append([y, x])
suma = 0
p1 = 0
p2 = 0
sol = 0
for p1 in range(n):
while p2 < n and b[p2][0] - b[p1][0] < d:
suma += b[p2][1]
p2 += 1
sol = max(sol, suma)
suma -= b[p1][1]
print(sol)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
n, d = I()
l = []
for x in range(n):
l.append(I())
l.sort()
an = max(i[1] for i in l)
i = 0
m = l[0][0]
c = 0
st = 0
while i < n:
if l[i][0] - m < d:
c += l[i][1]
else:
an = max(an, c)
while l[i][0] - l[st][0] >= d:
c -= l[st][1]
st += 1
m = l[st][0]
c += l[i][1]
i += 1
an = max(an, c)
print(an)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
lst = []
n, d = map(int, input().split())
for i in range(n):
mi, si = map(int, input().split())
lst.append([mi, si])
lst.sort()
f = 0
l = 0
ans = 0
a = 0
while l < n:
if lst[l][0] - lst[f][0] < d:
a += lst[l][1]
l += 1
else:
if a > ans:
ans = a
a -= lst[f][1]
f = f + 1
print(max(ans, a))
|
ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
line = [int(s) for s in input().split(" ")]
nr_friends = line[0]
friends = []
d = line[1]
for i in range(nr_friends):
line = [int(s) for s in input().split(" ")]
friends.append(line)
friends.sort()
max_sum = friends[0][1]
curr_sum = max_sum
remember = 0
i = 1
j = 0
while i < len(friends):
if abs(friends[i][0] - friends[j][0]) < d:
curr_sum += friends[i][1]
else:
while abs(friends[i][0] - friends[j][0]) >= d:
curr_sum -= friends[j][1]
j += 1
curr_sum += friends[i][1]
i += 1
max_sum = max(max_sum, curr_sum)
print(max_sum)
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
line = input().split()
n = int(line[0])
d = int(line[1])
friends = []
for i in range(n):
line = input().split()
friends.append([int(line[0]), int(line[1])])
friends = sorted(friends, key=lambda x: x[0], reverse=True)
i = 0
frCoef = 0
max = 0
for j in range(len(friends)):
frCoef += friends[j][1]
while abs(friends[i][0] - friends[j][0]) >= d:
frCoef -= friends[i][1]
i += 1
if frCoef > max:
max = frCoef
print(max)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST 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 ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, f = input().split()
n = int(n)
f = int(f)
a = []
for i in range(n):
x, y = input().split()
a.append((int(x), int(y)))
a = sorted(a)
s = a[0][1]
mx = s
k = 0
for i in range(1, len(a)):
if a[i][0] - a[k][0] < f:
s = s + a[i][1]
else:
s = s - a[k][1] + a[i][1]
for j in range(k + 1, i + 1):
if a[i][0] - a[j][0] < f:
s = s
k = j
break
else:
s = s - a[j][1]
k = j
if s > mx:
mx = s
print(mx)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = [int(x) for x in input().split()]
s = []
while n:
s.append([int(x) for x in input().split()])
n -= 1
s = sorted(s, key=lambda x: x[0], reverse=True)
st = 0
suma = 0
maxim = -1
for dr in range(len(s)):
suma += s[dr][1]
while abs(s[st][0] - s[dr][0]) >= d:
suma -= s[st][1]
st += 1
if suma > maxim:
maxim = suma
print(maxim)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
import sys
def solve(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, "r")
n, d = map(int, f.readline().split())
candidates = list()
for _ in range(n):
ab, at = map(int, f.readline().split())
candidates.append((ab, at))
candidates = sorted(candidates)
res = 0
temp = 0
i, j = 0, 0
while i < n and j < n:
if candidates[j][0] - candidates[i][0] < d:
temp += candidates[j][1]
res = max(res, temp)
j += 1
else:
temp -= candidates[i][1]
i += 1
return [f"{res}"]
def main():
for line in solve():
print(f"{line}")
main()
|
IMPORT FUNC_DEF NONE IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN LIST VAR FUNC_DEF FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.