description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
n, d = map(int, input().split())
a, b = map(int, input().split())
a2 = []
for i in range(n):
q, w = map(int, input().split())
a2.append((a * q + w * b, i))
a2.sort()
ans = []
sumz = 0
for i in range(n):
if sumz + a2[i][0] > d:
break
ans.append(a2[i][1])
sumz += a2[i][0]
print(len(ans))
for i in ans:
print(i + 1, end=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
n, d = tuple([int(z) for z in input().split(" ")])
a, b = tuple([int(z) for z in input().split(" ")])
c_arr = list()
for i in range(1, n + 1):
f, g = tuple(int(z) for z in input().split(" "))
t_arr = [f * a + g * b, i]
c_arr.append(t_arr)
c_arr.sort(key=lambda item: item[0])
r_arr = []
c = 0
i = 0
while i < len(c_arr) and c + c_arr[i][0] <= d:
c = c + c_arr[i][0]
r_arr.append(c_arr[i][1])
i = i + 1
print(len(r_arr))
print(" ".join([str(z) for z in r_arr]))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
n, d = map(int, input().split())
d1, d2 = map(int, input().split())
arr = [0] * n
for i in range(n):
a, b = map(int, input().split())
arr[i] = [d1 * a + d2 * b, i + 1]
arr.sort()
res, idx = 0, ""
for i in arr:
if d - i[0] < 0:
break
d -= i[0]
res += 1
idx += str(i[1]) + " "
print(res)
print(idx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 LIST BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER STRING FOR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
R = lambda: map(int, input().split())
n, d = R()
a, b = R()
def get():
x, y = R()
return a * x + b * y
s = sorted([(get(), i) for i in range(1, n + 1)])
ans = []
for i in range(n):
if d >= s[i][0]:
ans += [s[i][1]]
d -= s[i][0]
else:
break
print(len(ans))
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR LIST VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
n, d = map(int, input().split())
a, b = map(int, input().split())
x = []
for i in range(n):
q, w = map(int, input().split())
x.append([q, w, i + 1])
x.sort(key=lambda i: a * i[0] + b * i[1])
z = []
s = 0
for i in range(n):
if s + a * x[i][0] + b * x[i][1] <= d:
s = s + a * x[i][0] + b * x[i][1]
z.append(x[i][2])
print(len(z))
for i in z:
print(i, end=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
R = lambda: map(int, input().rstrip().split())
n, d = R()
a, b = R()
l = []
for i in range(n):
x, y = R()
cost = x * a + y * b
l.append([i + 1, cost])
l.sort(key=lambda x: x[1])
t = 0
cost = 0
i = 0
while i < n:
if cost + l[i][1] <= d:
cost += l[i][1]
i += 1
t += 1
else:
break
print(t)
for i in range(t):
print(l[i][0], end=" ")
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING
|
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
|
n, d = map(int, input().split())
a, b = map(int, input().split())
l = []
for i in range(1, n + 1):
a1, b1 = map(int, input().split())
l.append([a1 * a + b1 * b, i])
l.sort()
temp = d
ans = []
for i in l:
if i[0] <= temp:
ans.append(i[1])
temp -= i[0]
else:
break
print(len(ans))
print(*ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop to the other and back. There is at most one bus running between a pair of stops.
Polycarp made n trips on buses. About each trip the stop where he started the trip and the the stop where he finished are known. The trips follow in the chronological order in Polycarp's notes.
It is known that one trip on any bus costs a burles. In case when passenger makes a transshipment the cost of trip decreases to b burles (b < a). A passenger makes a transshipment if the stop on which he boards the bus coincides with the stop where he left the previous bus. Obviously, the first trip can not be made with transshipment.
For example, if Polycarp made three consecutive trips: "BerBank" $\rightarrow$ "University", "University" $\rightarrow$ "BerMall", "University" $\rightarrow$ "BerBank", then he payed a + b + a = 2a + b burles. From the BerBank he arrived to the University, where he made transshipment to the other bus and departed to the BerMall. Then he walked to the University and returned to the BerBank by bus.
Also Polycarp can buy no more than k travel cards. Each travel card costs f burles. The travel card for a single bus route makes free of charge any trip by this route (in both directions). Once purchased, a travel card can be used any number of times in any direction.
What is the smallest amount of money Polycarp could have spent today if he can buy no more than k travel cards?
-----Input-----
The first line contains five integers n, a, b, k, f (1 β€ n β€ 300, 1 β€ b < a β€ 100, 0 β€ k β€ 300, 1 β€ f β€ 1000) where: n β the number of Polycarp trips, a β the cost of a regualar single trip, b β the cost of a trip after a transshipment, k β the maximum number of travel cards Polycarp can buy, f β the cost of a single travel card.
The following n lines describe the trips in the chronological order. Each line contains exactly two different words separated by a single space β the name of the start stop and the name of the finish stop of the trip. All names consist of uppercase and lowercase English letters and have lengths between 1 to 20 letters inclusive. Uppercase and lowercase letters should be considered different.
-----Output-----
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
-----Examples-----
Input
3 5 3 1 8
BerBank University
University BerMall
University BerBank
Output
11
Input
4 2 1 300 1000
a A
A aa
aa AA
AA a
Output
5
-----Note-----
In the first example Polycarp can buy travel card for the route "BerBank $\leftrightarrow$ University" and spend 8 burles. Note that his second trip "University" $\rightarrow$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles.
In the second example it doesn't make sense to buy travel cards. Note that each of Polycarp trip (except the first) was made with transshipment. So the minimum total sum equals to 2 + 1 + 1 + 1 = 5 burles.
|
n, a, b, k, f = [int(i) for i in input().split()]
pred = "_"
d = dict()
for i in range(n):
s1, s2 = [i for i in input().split()]
pr = a
if s1 == pred:
pr = b
if (s1, s2) in list(d.keys()):
d[s1, s2] += pr
elif (s2, s1) in list(d.keys()):
d[s2, s1] += pr
else:
d[s1, s2] = pr
pred = s2
cn = k
ans = sum(d.values())
for i in sorted(list(d.values()), reverse=True):
if cn == 0 or i <= f:
break
ans = ans - i + f
cn -= 1
print(ans)
|
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop to the other and back. There is at most one bus running between a pair of stops.
Polycarp made n trips on buses. About each trip the stop where he started the trip and the the stop where he finished are known. The trips follow in the chronological order in Polycarp's notes.
It is known that one trip on any bus costs a burles. In case when passenger makes a transshipment the cost of trip decreases to b burles (b < a). A passenger makes a transshipment if the stop on which he boards the bus coincides with the stop where he left the previous bus. Obviously, the first trip can not be made with transshipment.
For example, if Polycarp made three consecutive trips: "BerBank" $\rightarrow$ "University", "University" $\rightarrow$ "BerMall", "University" $\rightarrow$ "BerBank", then he payed a + b + a = 2a + b burles. From the BerBank he arrived to the University, where he made transshipment to the other bus and departed to the BerMall. Then he walked to the University and returned to the BerBank by bus.
Also Polycarp can buy no more than k travel cards. Each travel card costs f burles. The travel card for a single bus route makes free of charge any trip by this route (in both directions). Once purchased, a travel card can be used any number of times in any direction.
What is the smallest amount of money Polycarp could have spent today if he can buy no more than k travel cards?
-----Input-----
The first line contains five integers n, a, b, k, f (1 β€ n β€ 300, 1 β€ b < a β€ 100, 0 β€ k β€ 300, 1 β€ f β€ 1000) where: n β the number of Polycarp trips, a β the cost of a regualar single trip, b β the cost of a trip after a transshipment, k β the maximum number of travel cards Polycarp can buy, f β the cost of a single travel card.
The following n lines describe the trips in the chronological order. Each line contains exactly two different words separated by a single space β the name of the start stop and the name of the finish stop of the trip. All names consist of uppercase and lowercase English letters and have lengths between 1 to 20 letters inclusive. Uppercase and lowercase letters should be considered different.
-----Output-----
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
-----Examples-----
Input
3 5 3 1 8
BerBank University
University BerMall
University BerBank
Output
11
Input
4 2 1 300 1000
a A
A aa
aa AA
AA a
Output
5
-----Note-----
In the first example Polycarp can buy travel card for the route "BerBank $\leftrightarrow$ University" and spend 8 burles. Note that his second trip "University" $\rightarrow$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles.
In the second example it doesn't make sense to buy travel cards. Note that each of Polycarp trip (except the first) was made with transshipment. So the minimum total sum equals to 2 + 1 + 1 + 1 = 5 burles.
|
n, a, b, k, f = list(map(int, input().split()))
totalCost = {}
lastStop = ""
total = 0
for i in range(n):
s1, s2 = input().split()
cost = a if lastStop != s1 else b
key = min(s1, s2), max(s1, s2)
if key not in totalCost:
totalCost[key] = cost
else:
totalCost[key] += cost
total += cost
lastStop = s2
sortedTotalCost = [(totalCost[key], key[0], key[1]) for key in totalCost]
sortedTotalCost.sort(reverse=True)
i = 0
while i < len(sortedTotalCost) and k > 0 and sortedTotalCost[i][0] > f:
total -= sortedTotalCost[i][0]
total += f
k -= 1
i += 1
print(total)
|
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop to the other and back. There is at most one bus running between a pair of stops.
Polycarp made n trips on buses. About each trip the stop where he started the trip and the the stop where he finished are known. The trips follow in the chronological order in Polycarp's notes.
It is known that one trip on any bus costs a burles. In case when passenger makes a transshipment the cost of trip decreases to b burles (b < a). A passenger makes a transshipment if the stop on which he boards the bus coincides with the stop where he left the previous bus. Obviously, the first trip can not be made with transshipment.
For example, if Polycarp made three consecutive trips: "BerBank" $\rightarrow$ "University", "University" $\rightarrow$ "BerMall", "University" $\rightarrow$ "BerBank", then he payed a + b + a = 2a + b burles. From the BerBank he arrived to the University, where he made transshipment to the other bus and departed to the BerMall. Then he walked to the University and returned to the BerBank by bus.
Also Polycarp can buy no more than k travel cards. Each travel card costs f burles. The travel card for a single bus route makes free of charge any trip by this route (in both directions). Once purchased, a travel card can be used any number of times in any direction.
What is the smallest amount of money Polycarp could have spent today if he can buy no more than k travel cards?
-----Input-----
The first line contains five integers n, a, b, k, f (1 β€ n β€ 300, 1 β€ b < a β€ 100, 0 β€ k β€ 300, 1 β€ f β€ 1000) where: n β the number of Polycarp trips, a β the cost of a regualar single trip, b β the cost of a trip after a transshipment, k β the maximum number of travel cards Polycarp can buy, f β the cost of a single travel card.
The following n lines describe the trips in the chronological order. Each line contains exactly two different words separated by a single space β the name of the start stop and the name of the finish stop of the trip. All names consist of uppercase and lowercase English letters and have lengths between 1 to 20 letters inclusive. Uppercase and lowercase letters should be considered different.
-----Output-----
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
-----Examples-----
Input
3 5 3 1 8
BerBank University
University BerMall
University BerBank
Output
11
Input
4 2 1 300 1000
a A
A aa
aa AA
AA a
Output
5
-----Note-----
In the first example Polycarp can buy travel card for the route "BerBank $\leftrightarrow$ University" and spend 8 burles. Note that his second trip "University" $\rightarrow$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles.
In the second example it doesn't make sense to buy travel cards. Note that each of Polycarp trip (except the first) was made with transshipment. So the minimum total sum equals to 2 + 1 + 1 + 1 = 5 burles.
|
def main():
trips, reg, cheap, cards, card_cost = list(map(int, input().split()))
costs = []
indexes = {}
total = 0
last = ""
for i in range(trips):
a, b = input().split()
pair = min(a, b), max(a, b)
if pair in indexes:
index = indexes[pair]
else:
costs.append(0)
indexes[pair] = len(costs) - 1
index = len(costs) - 1
total += cheap if a == last else reg
costs[index] += cheap if a == last else reg
last = b
costs = sorted(costs, reverse=True)
for c in costs:
if c < card_cost or cards <= 0:
break
total -= c
total += card_cost
cards -= 1
print(total)
main()
|
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop to the other and back. There is at most one bus running between a pair of stops.
Polycarp made n trips on buses. About each trip the stop where he started the trip and the the stop where he finished are known. The trips follow in the chronological order in Polycarp's notes.
It is known that one trip on any bus costs a burles. In case when passenger makes a transshipment the cost of trip decreases to b burles (b < a). A passenger makes a transshipment if the stop on which he boards the bus coincides with the stop where he left the previous bus. Obviously, the first trip can not be made with transshipment.
For example, if Polycarp made three consecutive trips: "BerBank" $\rightarrow$ "University", "University" $\rightarrow$ "BerMall", "University" $\rightarrow$ "BerBank", then he payed a + b + a = 2a + b burles. From the BerBank he arrived to the University, where he made transshipment to the other bus and departed to the BerMall. Then he walked to the University and returned to the BerBank by bus.
Also Polycarp can buy no more than k travel cards. Each travel card costs f burles. The travel card for a single bus route makes free of charge any trip by this route (in both directions). Once purchased, a travel card can be used any number of times in any direction.
What is the smallest amount of money Polycarp could have spent today if he can buy no more than k travel cards?
-----Input-----
The first line contains five integers n, a, b, k, f (1 β€ n β€ 300, 1 β€ b < a β€ 100, 0 β€ k β€ 300, 1 β€ f β€ 1000) where: n β the number of Polycarp trips, a β the cost of a regualar single trip, b β the cost of a trip after a transshipment, k β the maximum number of travel cards Polycarp can buy, f β the cost of a single travel card.
The following n lines describe the trips in the chronological order. Each line contains exactly two different words separated by a single space β the name of the start stop and the name of the finish stop of the trip. All names consist of uppercase and lowercase English letters and have lengths between 1 to 20 letters inclusive. Uppercase and lowercase letters should be considered different.
-----Output-----
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
-----Examples-----
Input
3 5 3 1 8
BerBank University
University BerMall
University BerBank
Output
11
Input
4 2 1 300 1000
a A
A aa
aa AA
AA a
Output
5
-----Note-----
In the first example Polycarp can buy travel card for the route "BerBank $\leftrightarrow$ University" and spend 8 burles. Note that his second trip "University" $\rightarrow$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles.
In the second example it doesn't make sense to buy travel cards. Note that each of Polycarp trip (except the first) was made with transshipment. So the minimum total sum equals to 2 + 1 + 1 + 1 = 5 burles.
|
n, a, b, k, f = [int(i) for i in input().split()]
stops = dict()
prev = ""
ans = 0
for i in range(n):
x, y = [i for i in input().split()]
price = a
if x == prev:
price = b
prev = y
p, q = min(x, y), max(x, y)
if (p, q) in stops:
stops[p, q] += price
else:
stops[p, q] = price
ans += price
edge_cost = sorted([stops[key] for key in stops], reverse=True)
for i in edge_cost:
if k > 0 and f < i:
ans = ans - i + f
else:
break
k -= 1
print(ans)
|
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In the evening Polycarp decided to analyze his today's travel expenses on public transport.
The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop to the other and back. There is at most one bus running between a pair of stops.
Polycarp made n trips on buses. About each trip the stop where he started the trip and the the stop where he finished are known. The trips follow in the chronological order in Polycarp's notes.
It is known that one trip on any bus costs a burles. In case when passenger makes a transshipment the cost of trip decreases to b burles (b < a). A passenger makes a transshipment if the stop on which he boards the bus coincides with the stop where he left the previous bus. Obviously, the first trip can not be made with transshipment.
For example, if Polycarp made three consecutive trips: "BerBank" $\rightarrow$ "University", "University" $\rightarrow$ "BerMall", "University" $\rightarrow$ "BerBank", then he payed a + b + a = 2a + b burles. From the BerBank he arrived to the University, where he made transshipment to the other bus and departed to the BerMall. Then he walked to the University and returned to the BerBank by bus.
Also Polycarp can buy no more than k travel cards. Each travel card costs f burles. The travel card for a single bus route makes free of charge any trip by this route (in both directions). Once purchased, a travel card can be used any number of times in any direction.
What is the smallest amount of money Polycarp could have spent today if he can buy no more than k travel cards?
-----Input-----
The first line contains five integers n, a, b, k, f (1 β€ n β€ 300, 1 β€ b < a β€ 100, 0 β€ k β€ 300, 1 β€ f β€ 1000) where: n β the number of Polycarp trips, a β the cost of a regualar single trip, b β the cost of a trip after a transshipment, k β the maximum number of travel cards Polycarp can buy, f β the cost of a single travel card.
The following n lines describe the trips in the chronological order. Each line contains exactly two different words separated by a single space β the name of the start stop and the name of the finish stop of the trip. All names consist of uppercase and lowercase English letters and have lengths between 1 to 20 letters inclusive. Uppercase and lowercase letters should be considered different.
-----Output-----
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
-----Examples-----
Input
3 5 3 1 8
BerBank University
University BerMall
University BerBank
Output
11
Input
4 2 1 300 1000
a A
A aa
aa AA
AA a
Output
5
-----Note-----
In the first example Polycarp can buy travel card for the route "BerBank $\leftrightarrow$ University" and spend 8 burles. Note that his second trip "University" $\rightarrow$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles.
In the second example it doesn't make sense to buy travel cards. Note that each of Polycarp trip (except the first) was made with transshipment. So the minimum total sum equals to 2 + 1 + 1 + 1 = 5 burles.
|
n, a, b, k, f = map(int, input().split())
slov = dict()
temp = input().split()
slov[frozenset(temp)] = a
for i in range(1, n):
temp2 = input().split()
try:
if temp2[0] == temp[1]:
slov[frozenset(temp2)] += b
else:
slov[frozenset(temp2)] += a
except KeyError:
if temp2[0] == temp[1]:
slov[frozenset(temp2)] = b
else:
slov[frozenset(temp2)] = a
temp = temp2
costs = sorted(list(slov.values()), reverse=True)
for i in range(min(k, len(costs))):
if costs[i] > f:
costs[i] = f
else:
break
print(sum(costs))
|
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort(key=lambda x: -x)
answer = 0
for i in range(n - 2):
v = 2 * a[i] - a[i + 1] - a[n - 1]
if v > answer:
answer = v
for j in range(2, n):
v = a[0] + a[j - 1] - 2 * a[j]
if v > answer:
answer = v
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def get_score(one, two, three):
return abs(one - two) + abs(two - three)
def solution(num_list: list, length: int):
num_list.sort()
high = 0
for i in range(length - 2):
value = num_list[i + 1] - num_list[i] + num_list[-1] - num_list[i]
if value > high:
high = value
for i in range(1, length - 1):
value = num_list[i + 1] - num_list[i] + num_list[i + 1] - num_list[0]
if value > high:
high = value
return high
t = int(input())
for _ in range(t):
n = int(input())
ln = list(map(int, input().split()))
print(solution(ln, n))
|
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = sorted(list(map(int, input().split())))
sum = 0
for i in range(n - 1):
sum = max(sum, abs(a[i + 1] - a[i] + abs(a[i] - a[n - 1])))
for i in range(1, n):
sum = max(sum, abs(a[i] - a[i - 1] + a[i] - a[0]))
print(sum)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for i in range(t):
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
ans = arr[n - 1] - arr[0]
for i in range(n - 1):
ans = max(
ans, arr[n - 1] + arr[i + 1] - 2 * arr[i], 2 * arr[i + 1] - arr[i] - arr[0]
)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def bar(A):
res = 0
for i in range(1, len(A) - 1):
ma = A[i - 1]
res = max(res, A[i] - ma + A[-1] - ma)
return res
def foo():
N = int(input())
A = sorted(list(map(int, input().strip().split())))
B = [(-x) for x in A][::-1]
return max(bar(A), bar(B))
T = int(input())
for _ in range(T):
print(foo())
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
while t > 0:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for i in range(1, n - 1):
ans = max(ans, a[i] - a[i - 1] + a[-1] - a[i - 1])
for i in range(1, n - 1):
ans = max(ans, a[-i] - a[-1 - i] + a[-i] - a[0])
print(ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
T = int(input())
for _ in range(T):
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [2 * a[-1] - a[0] - a[-2], a[-1] + a[1] - 2 * a[0]]
for i in range(1, n - 1):
b.append(max(a[i] - a[0] + a[i] - a[i - 1], a[-1] - a[i] + a[i + 1] - a[i]))
print(max(b))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
case = int(input())
for i in range(case):
n = int(input())
mas = list(map(int, input().split()))
mas.sort()
cur_max = 0
for j in range(1, len(mas) - 1):
cur_min = mas[j - 1]
cur_max = max(cur_max, mas[-1] - 2 * cur_min + mas[j])
cur_min = mas[len(mas) - j]
cur_max = max(cur_max, 2 * cur_min - mas[0] - mas[len(mas) - j - 1])
print(cur_max)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
T = int(input())
for tt in range(T):
n = int(input())
data = list(map(int, input().split()))
data = sorted(data)
subtract = []
for i in range(1, n):
subtract.append(data[i] - data[i - 1])
ans = 0
the_sum = sum(subtract)
for i in range(len(subtract) - 1):
ans = max(ans, the_sum + max(subtract[i], subtract[-1]))
the_sum -= subtract[i]
the_sum = sum(subtract)
for i in range(len(subtract) - 1, 0, -1):
ans = max(ans, the_sum + max(subtract[i], subtract[0]))
the_sum -= subtract[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def main():
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
m_a = min(a)
M_a = max(a)
init_val = max(M_a - m_a + a[1] - m_a, M_a - m_a + M_a - a[-2])
for i in range(1, n - 1):
val1 = M_a - a[i] + a[i + 1] - a[i]
j = n - i - 1
val2 = a[j] - m_a + a[j] - a[j - 1]
val = max(val1, val2)
if val > init_val:
init_val = val
print(init_val)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def solve() -> None:
n = int(input())
weights = list(map(int, input().split()))
weights.sort()
ans = 0
for i in range(2, n):
ans = max(ans, weights[i] - weights[i - 1] + weights[i] - weights[0])
for i in range(1, n - 1):
ans = max(ans, weights[i] - weights[i - 1] + weights[-1] - weights[i - 1])
print(ans)
tt = int(input())
for _ in range(tt):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for i in range(t):
n = int(input())
lis = [int(i) for i in input().split()]
lis.sort()
max = 0
for i in range(2, n):
if max < 2 * lis[i] - lis[i - 1] - lis[0]:
max = 2 * lis[i] - lis[i - 1] - lis[0]
for i in range(n - 1):
if max < lis[i + 1] + lis[n - 1] - 2 * lis[i]:
max = lis[i + 1] + lis[n - 1] - 2 * lis[i]
print(max)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
mnToMx = 0
for i in range(n - 2):
mnToMx = max(mnToMx, abs(a[i] - a[i + 1]) + abs(a[i] - a[n - 1]))
mxToMn = 0
i = n - 1
while i >= 2:
mxToMn = max(mxToMn, abs(a[i] - a[i - 1]) + abs(a[i] - a[0]))
i -= 1
print(max(mxToMn, mnToMx))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
while t > 0:
n = int(input())
b = list(map(int, input().split()))
b.sort()
ans = 0
first = b[0]
last = b[-1]
for bri in range(2, n):
br = b[bri]
ans1 = br - first + br - b[bri - 1]
if ans1 > ans:
ans = ans1
for bri in range(0, n - 2):
br = b[bri]
ans1 = last - br + b[bri + 1] - br
if ans1 > ans:
ans = ans1
print(ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
while t > 0:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = abs(a[0] - a[n - 1]) + abs(a[n - 1] - a[n - 2])
ans = max(ans, abs(a[n - 1] - a[0]) + abs(a[0] - a[1]))
for i in range(2, n):
ans = max(ans, abs(a[0] - a[i]) + abs(a[i] - a[i - 1]))
for i in range(0, n - 2):
ans = max(ans, abs(a[n - 1] - a[i]) + abs(a[i] - a[i + 1]))
print(ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort()
for i in range(n - 1):
ans = max(ans, a[n - 1] + a[i] - 2 * a[i - 1], 2 * a[i + 1] - a[i] - a[0])
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for _ in range(t):
n = int(input())
lst_a = sorted(map(int, input().split()))
mx = 0
for j in range(n):
mx = max(mx, 2 * lst_a[j] - lst_a[0] - lst_a[j - 1])
for j in range(n - 1):
mx = max(mx, lst_a[-1] + lst_a[j + 1] - 2 * lst_a[j])
print(mx)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
T = int(input())
for kse in range(T):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n - 1):
ans = max(
ans,
max(a[i + 1] - a[0] + a[i + 1] - a[i], a[n - 1] - a[i] + a[i + 1] - a[i]),
)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
arr = sorted(list(map(int, input().split())))
ans = arr[-1] - arr[0]
for i in range(n - 1):
b1 = arr[i + 1]
b2 = arr[-1]
b3 = arr[0]
ans = max(ans, b1 + b2 - 2 * arr[i], 2 * b1 - arr[i] - b3)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mx = a[-1]
mn = a[0]
a1 = a[0]
an_1 = a[-1]
for e in a:
if e != mn:
a1 = e
break
for i in range(n - 1, -1, -1):
if a[i] != mx:
an_1 = a[i]
break
ans = max(2 * a[-1] - a[0] - an_1, a[-1] - a[0] + a1 - a[0])
pre = a1
for i in range(2, n):
if a[i] != pre:
ans = max(ans, 2 * a[i] - a[0] - pre)
pre = a[i]
pre = an_1
for i in range(n - 2, -1, -1):
if a[i] != pre:
ans = max(ans, mx - a[i] + pre - a[i])
pre = a[i]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(1, n - 1):
res = max((res, 2 * l[i + 1] - l[0] - l[i], l[n - 1] + l[i] - 2 * l[i - 1]))
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().strip().split()))
co = 0
l = list(set(l))
l.sort()
n = len(l)
if n <= 1:
co = 0
elif n == 2:
co = 2 * (l[1] - l[0])
else:
co = l[-1] - l[0] + max(l[-1] - l[-2], l[1] - l[0])
a = l[-1] - l[1] + l[2] - l[1]
b = l[-2] - l[0] + l[-2] - l[-3]
co = max(a, b, co)
for i in range(2, n - 2):
c = l[-1] - l[i] + l[i + 1] - l[i]
e = l[i] - l[0] + l[i] - l[i - 1]
co = max(co, c, e)
print(co)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def solve(arr, n):
arr.sort()
maxx = 0
for i in range(1, n - 1):
maxx = max(maxx, abs(arr[i + 1] - arr[0]) + abs(arr[i + 1] - arr[i]))
for i in range(0, n - 2):
maxx = max(maxx, abs(arr[n - 1] - arr[i]) + abs(arr[i + 1] - arr[i]))
print(maxx)
for _ in range(int(input())):
n = int(input())
arr = [int(x) for x in input().split()]
solve(arr, n)
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def sol(lst):
res = 0
lst.sort()
for i in range(1, n):
res = max(res, 2 * lst[i] - lst[i - 1] - lst[0])
for i in reversed(range(len(lst) - 2)):
res = max(res, lst[n - 1] + lst[i + 1] - 2 * lst[i])
return res
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
lst = list(map(int, input().split()))
s = sol(lst)
print(s)
|
FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def solve():
n = int(input())
a = list(map(int, input().split()))
a.sort()
v1 = 0
v2 = 0
for i in range(n - 1, 1, -1):
v1 = max(2 * a[i] - a[i - 1] - a[0], v1)
for i in range(0, n - 2):
v2 = max(a[i + 1] + a[-1] - 2 * a[i], v2)
return max(v1, v2)
for t in range(0, int(input())):
print(solve())
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
maxx = 0
for j in range(2, n):
maxx = max(maxx, abs(a[0] - a[j]) + abs(a[j] - a[j - 1]))
for k in range(n - 2):
maxx = max(maxx, abs(a[n - 1] - a[k]) + abs(a[k] - a[k + 1]))
print(maxx)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
casecnt = int(input())
for case in range(casecnt):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
bestscore = 0
for i in range(1, n):
g = a[i] - a[i - 1]
score = g
score += max(a[i] - a[0], a[n - 1] - a[i - 1])
bestscore = max(score, bestscore)
print(bestscore)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def N():
return int(input())
def A():
return [int(x) for x in input().split()]
def S():
return input()
for _ in range(N()):
n = N()
if "codeforces" == 28226329:
print("Tanmay")
a = A()
a.sort()
ans = 0
for i in range(n - 1):
ans = max(ans, abs(a[i + 1] - a[i]) + abs(a[i] - a[n - 1]))
for i in range(1, n):
ans = max(ans, abs(a[i] - a[i - 1]) + a[i] - a[0])
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
import sys
def read():
return [int(x) for x in sys.stdin.readline().split(" ")]
[t] = read()
for _ in range(t):
[n] = read()
A = read()
A.sort()
res = A[n - 1] - A[0]
for i in range(1, n - 1):
res = max(res, 2 * A[i + 1] - A[i] - A[0])
for i in range(0, n - 2):
res = max(res, A[n - 1] + A[i + 1] - 2 * A[i])
print(res)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN LIST VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
mx = -1
l = list(map(int, input().split()))
l.sort()
for i in range(n - 1):
mx = max(mx, l[-1] - l[i] + l[i + 1] - l[i])
mx = max(mx, abs(l[i + 1] - l[i]) + abs(l[i + 1] - l[0]))
print(mx)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def brick():
t = int(input())
for i in range(t):
n = int(input())
para = input().split(" ")
bri = [int(x) for x in para]
bri.sort()
s, l = bri[0], bri[-1]
e1 = l - s + max(min(bri[1:-1]) - s, l - max(bri[1:-1]))
for i in range(1, len(bri) - 1):
e2 = l - bri[i - 1] + bri[i] - bri[i - 1]
e3 = bri[i + 1] - bri[i] + bri[i + 1] - s
e1 = max(e1, e2, e3)
print(e1)
brick()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for i in range(t):
n = int(input())
l = list(map(int, input().split()))
l.sort()
maxi = 0
for i in range(0, len(l) - 2):
ans1 = abs(l[i] - l[-1]) + abs(l[-1] - l[-2])
ans2 = abs(l[-1] - l[i]) + abs(l[i] - l[i + 1])
maxi = max(maxi, ans1, ans2)
l.sort(reverse=True)
maxim = 0
for j in range(0, len(l) - 2):
ans1 = abs(l[j] - l[-1]) + abs(l[-1] - l[-2])
ans2 = abs(l[-1] - l[j]) + abs(l[j] - l[j + 1])
maxim = max(maxim, ans1, ans2)
ans = max(maxi, maxim)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for i in range(1, n - 1):
ans = max(ans, l[i] - l[i - 1] + l[-1] - l[i - 1])
l = l[::-1]
for i in range(1, n - 1):
ans = max(ans, l[i - 1] - l[i] + l[i - 1] - l[-1])
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for j in range(0, t):
n = int(input())
l = list(map(int, input().split()))
l.sort()
s = 0
for k in range(0, n):
if k == 0:
s = max(s, abs(l[k] - l[n - 1]) + abs(l[k] - l[1]))
elif k == n - 1:
s = max(s, abs(l[k] - l[0]) + abs(l[n - 2] - l[k]))
else:
f = max(
abs(l[k] - l[0]) + abs(l[k] - l[k - 1]),
abs(l[k] - l[0]) + abs(l[k] - l[k + 1]),
)
f1 = max(
abs(l[k] - l[n - 1]) + abs(l[k] - l[k - 1]),
abs(l[k] - l[n - 1]) + abs(l[k] - l[k + 1]),
)
f = max(f, f1)
s = max(s, f)
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def f(arr):
s_arr = sorted(arr)
res = 0
for i in range(len(arr) - 2):
res = max([res, s_arr[i + 1] - s_arr[i] + s_arr[-1] - s_arr[i]])
for i in range(len(arr) - 1, 1, -1):
res = max([res, s_arr[i] - s_arr[i - 1] + s_arr[i] - s_arr[0]])
return res
t = int(input())
for i in range(t):
n = int(input())
arr = [int(el) for el in input().split(" ")]
print(f(arr))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(n):
if i < n - 2:
res = A[i + 1] - A[i] + A[n - 1] - A[i]
ans = max(ans, res)
if i >= 2:
res = A[i] - A[i - 1] + A[i] - A[0]
ans = max(ans, res)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input(""))
for j in range(t):
n = int(input(""))
l = list(map(int, input("").split()))
l.sort()
m = 0
for i in range(-1, -len(l) + 1, -1):
a = l[i] + l[i] - l[i - 1] - l[0]
if m < a:
m = a
for i in range(0, n - 2):
a = l[-1] + l[i + 1] - l[i] - l[i]
if m < a:
m = a
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
def sol(lst):
lst.sort()
maxi = 0
for i in range(2, len(lst)):
maxi = max(maxi, abs(lst[i] - lst[i - 1]) + abs(lst[i] - lst[0]))
for i in reversed(range(len(lst) - 2)):
maxi = max(maxi, abs(lst[i] - lst[i + 1]) + abs(lst[i] - lst[-1]))
return maxi
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
lst = [int(s) for s in input().split(" ")]
s = sol(lst)
print(s)
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for _ in range(t):
n = int(input())
w = list(map(int, input().split(" ")))
w1 = sorted(w)
w2 = sorted(w, reverse=True)
answer = 0
for i in range(n - 2):
answer = max(
answer,
abs(w1[i] - w1[i + 1]) + abs(w1[i] - w1[n - 1]),
abs(w2[i] - w2[i + 1]) + abs(w2[i] - w2[n - 1]),
)
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for t1 in range(t):
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(n - 1):
mx = a[i + 1] - a[i] + max(a[i + 1] - a[0], a[-1] - a[i])
if mx > ans:
ans = mx
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for _ in range(t):
input()
temp = input().split()
l = [int(v) for v in temp]
l.sort()
largest = 0
for b in range(0, len(l) - 2):
m = abs(l[b] - l[b + 1]) + abs(l[b] - l[-1])
if m > largest:
largest = m
l.reverse()
for b in range(0, len(l) - 2):
m = abs(l[b] - l[b + 1]) + abs(l[b] - l[-1])
if m > largest:
largest = m
print(largest)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
for T in range(int(input())):
n = int(input())
a = sorted(list(map(int, input().split())))
ans = a[n - 1] - a[0]
for i in range(2, n):
ans = max(ans, a[i] - a[0] + a[i] - a[i - 1])
for i in range(0, n - 1):
ans = max(ans, a[i + 1] - a[i] + a[n - 1] - a[i])
ans = max(ans, a[n - 1] - 2 * a[0] + a[1])
ans = max(ans, 2 * a[n - 1] - a[0] - a[n - 2])
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
out = []
def solve(arr):
arr = sorted(arr)
max1 = abs(arr[-1] - arr[-2]) + abs(arr[-1] - arr[0])
for i in range(len(arr) - 2, 1, -1):
temp = abs(arr[i] - arr[i - 1]) + abs(arr[i] - arr[0])
if temp > max1:
max1 = temp
max2 = abs(arr[-1] - arr[-3]) + abs(arr[-2] - arr[-3])
for i in range(len(arr) - 3, 0, -1):
temp = abs(arr[i] - arr[i - 1]) + abs(arr[i - 1] - arr[-1])
if temp > max2:
max2 = temp
return max(max1, max2)
for tc in range(t):
n = int(input())
arr = []
arr = map(int, input().split())
out.append(solve(arr))
for o in out:
print(o)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$.
Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.
After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$.
It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) β the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) β the number of bricks.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the weights of the bricks.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.
-----Examples-----
Input
3
5
3 1 5 2 3
4
17 8 19 45
8
265 265 265 265 265 265 265 265
Output
6
63
0
-----Note-----
In the first test case, one way of achieving a final score of $6$ is to do the following:
Put bricks $1$, $4$, and $5$ into bag $1$.
Put brick $3$ into bag $2$.
Put brick $2$ into bag $3$.
If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:
Take brick $5$ from bag $1$.
Take brick $3$ from bag $2$.
Take brick $2$ from bag $3$.
The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.
It can be shown that there is no other distribution that results in a final score bigger than $6$.
|
t = int(input())
for j in range(t):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
max = a[n - 1] - a[0]
for i in range(0, len(a) - 1):
if max < a[n - 1] - a[i] + a[i + 1] - a[i]:
max = a[n - 1] - a[i] + a[i + 1] - a[i]
for i in range(len(a) - 1, 0, -1):
if max < a[i] - a[0] + a[i] - a[i - 1]:
max = a[i] - a[0] + a[i] - a[i - 1]
print(max)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
inp = [int(x) for x in input().split()]
n, m = inp[:2]
k = inp[-1]
l = [int(x) for x in input().split()]
arr = [[i, j] for i, j in enumerate(l)]
arr = sorted(arr, key=lambda x: x[1], reverse=True)
summ = 0
for i in range(m * k):
summ += arr[i][1]
print(summ)
rs = [(i[0] + 1) for i in arr[: m * k]]
rs.sort()
frs = []
for i in range(m - 1, m * (k - 1), m):
frs.append(str(rs[i]))
print(" ".join(frs))
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
[n, m, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
b = a[:]
b.sort(reverse=True)
can = b[m * k - 1]
last = 0
for i in range(m * k, len(b)):
if b[i] == can:
last += 1
else:
break
ans = 0
for i in range(m * k):
ans += b[i]
print(ans)
num = 0
ans = []
for i in range(len(a)):
if a[i] >= can:
if last > 0 and a[i] == can:
last -= 1
else:
num += 1
if num >= m:
ans.append(i + 1)
num = 0
if len(ans) == k - 1:
break
print(" ".join(str(i) for i in ans))
|
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
ind = list(sorted(range(n), key=lambda i: a[i], reverse=True))
ind2 = list(sorted(ind[: m * k]))
print(sum(a[i] for i in ind2))
for i in range(k - 1):
print(ind2[i * m + m - 1] + 1, end=" ")
print()
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
def rli():
return list(map(int, input().split()))
def main():
n, m, k = rli()
nums = rli()
x = []
for i in range(len(nums)):
x.append((nums[i], i))
choosed = [0] * len(nums)
tot = 0
x.sort()
x = x[-1::-1]
for i in range(m * k):
tot += x[i][0]
choosed[x[i][1]] = 1
ans = []
cnt = 0
for i in range(len(nums)):
if choosed[i]:
cnt += 1
cnt %= m
if cnt == 0:
ans.append(i + 1)
print(tot)
print(" ".join(map(str, ans[:-1])))
main()
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
l = list(map(int, input().split()))
a = list(map(int, input().split()))
b = a[:]
b.sort(reverse=True)
minn = b[l[2] * l[1] - 1]
cnt = 0
summ = 0
for i in range(l[2] * l[1]):
summ = summ + b[i]
if b[i] > minn:
cnt = cnt + 1
minn_cnt = l[2] * l[1] - cnt
y = l[2] - 1
lenn = 0
i = 0
index = []
while y > 0:
if a[i] > minn:
lenn = lenn + 1
if minn_cnt > 0 and a[i] == minn:
lenn = lenn + 1
minn_cnt = minn_cnt - 1
if lenn == l[1]:
y = y - 1
lenn = 0
index.append(i + 1)
i = i + 1
print(summ)
print(*index)
|
ASSIGN 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 ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
arr = list(zip(range(n), map(int, input().split())))
arr.sort(key=lambda x: x[1], reverse=True)
arr = arr[: m * k]
arr.sort(key=lambda x: x[0])
ans = []
for i in range(m, m * k, m):
ans.append(arr[i][0])
print(sum([x[1] for x in arr]))
print(*ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
import sys
n, m, k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
arr = []
for i in range(n):
arr.append([a[i], i])
arr.sort(reverse=True)
index = []
ans = 0
for i in range(m * k):
ans += arr[i][0]
index.append(arr[i][1])
index.sort()
print(ans)
ans1 = []
for i in range(k - 1):
ans1.append(index[(i + 1) * m - 1] + 1)
print(*ans1)
|
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
list_int_input = lambda inp: list(map(int, inp.split()))
int_input = lambda inp: int(inp)
string_to_list_input = lambda inp: list(inp)
n, m, k = map(int, input().split())
a = list_int_input(input())
a = [(ind, val) for ind, val in enumerate(a)]
a.sort(key=lambda x: x[1])
a = a[n - m * k :]
a.sort(key=lambda x: x[0])
summ = sum([pair[1] for pair in a])
i = m
print(summ)
while i != k * m:
print(a[i][0], end=" ")
i += m
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING VAR VAR EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
r = list(map(int, input().split()))
r = [[r[i], i] for i in range(n)]
r.sort(reverse=True)
ans = 0
ind = [0] * (m * k)
for i in range(m * k):
ans += r[i][0]
ind[i] = r[i][1]
ind.sort()
print(ans)
for i in range(k - 1):
print(ind[(i + 1) * m - 1] + 1, end=" ")
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER STRING
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
l = input().split()
n = int(l[0])
m = int(l[1])
k = int(l[2])
l = input().split()
li = [int(i) for i in l]
lfi = []
for i in range(n):
lfi.append((int(l[i]), i))
lfi.sort()
lfi.reverse()
hashi = dict()
summax = 0
for i in range(m * k):
summax += lfi[i][0]
hashi[lfi[i][1]] = 1
lpart = []
tillnow = 0
for i in range(n):
if i in hashi:
tillnow += 1
if tillnow == m:
lpart.append(i)
tillnow = 0
print(summax)
for i in range(k - 1):
print(lpart[i] + 1, end=" ")
print()
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a, reverse=True)
d = dict()
s = 0
for i in b[: m * k]:
s += i
if i in d:
d[i] += 1
else:
d[i] = 1
ans = []
prev = 0
for i in range(k - 1):
count = 0
pos = prev
while count < m:
if a[pos] in d and d[a[pos]] > 0:
d[a[pos]] -= 1
count += 1
pos += 1
prev = pos
ans.append(str(pos))
print(s)
print(" ".join(ans))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
lis = list(map(int, input().split()))
aa = sorted(range(len(lis)), key=lambda k: lis[k], reverse=True)
t = m * k
aa = aa[:t]
aa.sort()
p = 0
for i in aa:
p += lis[i]
ans = []
i = m
while i < len(aa):
ans.append(aa[i - 1] + 1)
i += m
print(p)
print(*ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = []
for i in range(len(arr1)):
arr2.append((arr1[i], i))
arr2.sort(reverse=True)
arr3 = []
ans = 0
for i in range(m * k):
ans += arr2[i][0]
arr3.append(arr2[i][1])
arr3.sort()
ansarr = []
count = 0
for i in range(m * k - m):
if (i + 1) % m == 0:
ansarr.append(arr3[i] + 1)
print(ans)
print(*ansarr)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
tot = []
i = 0
counter = 0
total = []
for item in a:
tot.append((item, i))
i += 1
tot.sort(reverse=True)
for i in range(m * k):
total.append(tot[i][1])
counter += tot[i][0]
total.sort()
answer = []
for i in range(m, len(total), m):
answer.append(total[i])
print(counter)
print(*answer)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
arr = [(arr[i], i) for i in range(n)]
arr.sort(reverse=True)
lis = []
ans = 0
for i in range(m * k):
ans += arr[i][0]
lis.append(arr[i][1])
lis.sort()
a1 = []
for i in range(m - 1, len(lis), m):
a1.append(lis[i] + 1)
print(ans)
print(*a1[:-1])
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
c = [i for i in range(n)]
c.sort(key=lambda x: arr[x])
res = c[n - m * k :]
res.sort()
total = 0
for i in res:
total += arr[i]
print(total)
for i in range(m - 1, len(res) - 1, m):
print(res[i] + 1, end=" ")
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
vec = list(map(int, input().split()))
must = []
for i in range(n):
must.append([vec[i], i])
must.sort(reverse=True)
mustLen = m * k
ans = 0
spl = [0] * (n + 1)
for i in range(0, mustLen):
spl[must[i][1]] = 1
ans += must[i][0]
cur = 0
print(ans)
for i in range(n):
cur += spl[i]
if cur == m and k > 1:
print(i + 1, end=" ")
cur = 0
k -= 1
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
def find_lower_bound(array, n, m, k):
tmp_array = sorted(array, reverse=1)
cnt = 0
for i in range(n):
if tmp_array[i] > tmp_array[m * k - 1]:
cnt += 1
else:
break
return [tmp_array[m * k - 1], m * k - cnt]
def find_beauty(array, upper_bound, lower_bound, m):
tmp_array = sorted(array, reverse=1)
out = 0
for i in range(m):
out += tmp_array[i]
return out
def partition(array, n, m, k, lower_bound, number):
out = []
sum_of_beauty = 0
i = 0
while i < n:
cnt = 0
for j in range(i, n):
if array[j] > lower_bound:
cnt += 1
sum_of_beauty += array[j]
elif array[j] == lower_bound and number > 0:
cnt += 1
sum_of_beauty += array[j]
number -= 1
if cnt == m:
out.append(j + 1)
k -= 1
i += 1
break
i += 1
if k == 0:
break
print(sum_of_beauty)
return out
n, m, k = map(int, input().split())
array = list(map(int, input().split()))
lower_bound, number = find_lower_bound(array, n, m, k)
res = partition(array, n, m, k, lower_bound, number)
for i in range(len(res) - 1):
print(res[i], end=" ")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN LIST VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
ar = list(map(int, input().split()))
pos = []
for i in range(n):
pos.append([i, ar[i]])
st = sorted(pos, key=lambda a: a[1], reverse=True)
s = 0
for i in range(m * k):
s += st[i][1]
print(s)
req = st[: m * k]
req.sort(key=lambda a: a[0])
ct = 0
z = 0
for i in range(0, m * k, m):
if z:
print(req[i][0], end=" ")
ct += 1
z = 1
if ct == k - 1:
break
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
_ = input()
n, m, k = _.split()
n, m, k = int(n), int(m), int(k)
_ = input()
a = _.split()
a = [(i, int(value)) for i, value in enumerate(a)]
position = []
b = sorted(a, key=lambda p: p[1])
b = b[-m * k :]
answer = 0
for i in b:
answer = answer + i[1]
print(answer)
answer = ""
position = [(p[0] + 1) for p in b]
position.sort()
position.pop()
for i, p in enumerate(position):
if i % m == m - 1:
answer = answer + "{} ".format(p)
print(answer)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
def answer(n, m, k, A):
count = 0
l = sorted(A)
maxi = 0
d = {}
for i in range(n - 1, -1, -1):
if count == m * k:
break
if l[i] in d:
d[l[i]] += 1
else:
d[l[i]] = 1
maxi += l[i]
count += 1
ans = []
count = 0
for i in range(n):
if A[i] in d:
if d[A[i]] > 0:
count += 1
d[A[i]] -= 1
if count == m:
ans.append(i + 1)
count = 0
ans.pop()
return maxi, ans
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
a, b = answer(n, m, k, arr)
print(a)
print(*b)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
[n, m, k] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
sort = sorted(a)
sort.reverse()
comparison = sort[m * k - 1]
num_comparison = sort[: m * k].count(comparison)
partition_count = 0
output = []
curr_k = k
for i in range(n):
if a[i] > comparison or a[i] == comparison and num_comparison:
partition_count += 1
if partition_count == m:
output.append(str(i + 1))
partition_count = 0
curr_k -= 1
if num_comparison and a[i] == comparison:
num_comparison -= 1
if curr_k == 1:
break
print(sum(sort[: m * k]))
print(" ".join(output))
|
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
def main():
arr = input().split()
n = int(arr[0])
m = int(arr[1])
k = int(arr[2])
arr = input().split()
store = []
for x in range(n):
arr[x] = int(arr[x])
store.append(arr[x])
store.sort()
bound = store[-(m * k)]
count = 0
total = 0
for x in range(-(m * k), 0):
if store[x] == bound:
count += 1
total += int(store[x])
print(total)
total = 0
subcount = 0
outs = 0
for x in range(n):
if arr[x] > bound:
subcount += 1
total += int(arr[x])
elif arr[x] == bound and count > 0:
subcount += 1
count -= 1
total += int(arr[x])
if subcount == m:
subcount = 0
outs += 1
print(x + 1, end=" ")
if outs == k - 1:
break
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER 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 IF VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = [int(s) for s in input().split(" ")]
array = [int(s) for s in input().split(" ")]
index = sorted(range(len(array)), key=lambda k: array[k], reverse=True)
index = sorted(index[: m * k])
out = index[m - 1 :: m][:-1]
print(sum(array[i] for i in index))
print(" ".join(str(i + 1) for i in out))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
l = [int(i) for i in input().split()]
z = m * k
l1 = [[l[i], i] for i in range(n)]
l1.sort(key=lambda x: -x[0])
req = []
sm = 0
for i in range(z):
req.append(l1[i][1])
sm += l1[i][0]
req.sort()
print(sm)
cnt = 0
for i in range(len(req)):
cnt += 1
if cnt % m == 0 and i != z - 1:
print(req[i] + 1, end=" ")
cnt = 0
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
b.append([a[i], i])
def sortFirst(val):
return val[0]
b.sort(key=sortFirst, reverse=True)
jog = 0
ind = []
for i in range(m * k):
jog += b[i][0]
ind.append(b[i][1] + 1)
ind.sort()
l = m - 1
ans = [ind[l]]
for i in range(k - 2):
ans.append(ind[l + m])
l += m
print(jog)
print(*ans, sep=" ")
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = list(map(int, input().split(" ")))
std_in = list(map(int, input().split(" ")))
a = [(std_in[i], i) for i in range(n)]
a = sorted(a, key=lambda x: x[0], reverse=True)
largest = a[: m * k]
print(sum([i[0] for i in largest]))
ind = sorted(largest, key=lambda x: x[1])
print(" ".join([str(ind[m * i - 1][1] + 1) for i in range(1, k)]))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
indexed_a = zip(a, list(range(n)))
sorted_indexed_a = list(reversed(sorted(indexed_a)))
sorted_a = list(reversed(sorted(a)))
partition = list(sorted([y for x, y in sorted_indexed_a[: m * k]]))
print(sum(sorted_a[: m * k]))
result = [(x + 1) for x in partition[m - 1 :: m]]
print(" ".join([str(x) for x in result[:-1]]))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
x = sorted(a, reverse=True)
d = {}
for i in range(m * k):
if x[i] in d:
d[x[i]] += 1
else:
d[x[i]] = 1
indx = []
c = 0
for i in range(n):
if a[i] in d:
c += 1
d[a[i]] -= 1
if d[a[i]] == 0:
del d[a[i]]
if c == m:
c = 0
indx.append(i + 1)
print(sum(x[: m * k]))
print(*indx[:-1])
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
b.sort()
mn = 10**18
q = 0
for i in range(n):
b.append([a[i], i])
b.sort(reverse=True)
l = 0
ind = []
for i in range(m * k):
q += b[i][0]
ind.append(b[i][1])
ind.sort()
ans = []
for i in range(len(ind)):
l += 1
if l % m == 0:
ans.append(ind[i] + 1)
print(q)
print(*ans[0 : len(ans) - 1])
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
from sys import stdin, stdout
n, m, k = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
I = list(reversed(sorted(range(n), key=lambda i: A[i])))
S = set(I[: m * k])
ans = []
count = 0
for i in range(n):
if i in S:
count += 1
if count == m:
ans.append(i + 1)
count = 0
ans.pop()
print(sum(A[i] for i in S))
print(" ".join(str(x) for x in ans))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
[n, m, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(a)
b.sort(reverse=True)
pool = dict()
val = 0
for i in range(m * k):
if b[i] in pool:
pool[b[i]] += 1
else:
pool[b[i]] = 1
val += b[i]
res = list()
hit = 0
for i in range(n):
if a[i] in pool and pool[a[i]] > 0:
pool[a[i]] -= 1
hit += 1
if hit == m and len(res) + 1 < k:
res.append(i + 1)
hit = 0
print(val)
print(" ".join(map(str, res)))
|
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
b.sort(reverse=True)
s = 0
c = {}
for i in range(m * k):
s += b[i]
c[b[i]] = c.get(b[i], 0) + 1
print(s)
ans = []
ms = m
for i in range(n):
if c.get(a[i], 0) > 0:
c[a[i]] -= 1
ms -= 1
if ms == 0:
ms = m
ans.append(str(i + 1))
ans.pop()
print(" ".join(ans))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
def make_string(ans):
sss = ""
for index, value in enumerate(ans):
if index:
sss += " "
sss += str(value)
return sss
def each():
n, m, k = [int(x) for x in input().split(" ")]
arr = [[int(value), index] for index, value in enumerate(input().split(" "))]
arr.sort()
sum = 0
len = n - min(m * k, n) - 1
for i in range(n - 1, len, -1):
sum += arr[i][0]
arr[i][0] = None
arr.sort(key=lambda x: x[1:2])
mmm = m
ans = []
for i in range(n):
if arr[i][0] == None:
mmm -= 1
if mmm == 0:
mmm = m
ans.append(arr[i][1] + 1)
ans.pop()
print(sum)
ans = make_string(ans)
print(ans)
each()
|
FUNC_DEF ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NONE EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NONE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(range(len(a)), key=lambda i: a[i], reverse=True)
b = b[: m * k]
b.sort()
sum = 0
for i in b:
sum += a[i]
print(sum)
b = b[m - 1 : -1 : m]
for i in b:
print(i + 1, end=" ")
print()
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
p = [(0, 0)] * n
for i in range(n):
p[i] = i, a[i]
s = sorted(p, key=lambda g: g[1], reverse=True)
s = s[: k * m]
s = sorted(s, key=lambda g: g[0])
h = 0
for i in range(len(s)):
h += s[i][1]
print(h)
l = []
for i in range(1, k):
l.append(s[i * m][0])
print(*l)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
R = lambda: map(int, input().split())
n, m, k = R()
a, b = zip(*sorted(zip(R(), range(1, n + 1)))[-m * k :])
print(sum(a), *sorted(b)[m - 1 : -1 : m])
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = (int(t) for t in input().split(" "))
a = [int(t) for t in input().split(" ")]
s = list(enumerate(a))
s.sort(key=lambda x: x[1], reverse=True)
s = s[: m * k]
print(sum(x[1] for x in s))
s = [x[0] for x in s]
s.sort()
print(*[(s[i - 1] + 1) for i in range(m, m * k, m)])
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
x = sorted(sorted(range(1, n + 1), key=lambda i: a[i - 1], reverse=True)[: m * k])
print(sum(a[i - 1] for i in x))
print(*x[m - 1 : -1 : m])
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
check = [False] * n
res = 0
for i in range(n):
a[i] = a[i], i
a.sort(reverse=True)
for i in range(m * k):
check[a[i][1]] = True
res += a[i][0]
print(res)
ht = 0
for i in range(n):
if check[i]:
ht += 1
if ht == m:
k -= 1
if k == 0:
break
print(i + 1, end=" ", flush=False)
ht = 0
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
read = lambda: map(int, input().split())
def takeFirst(element):
return element[0]
def takeSecond(element):
return element[1]
n, m, k = read()
a = list(read())
b = []
for cnt, x in enumerate(a):
b.append([cnt, x])
b.sort(key=takeSecond, reverse=True)
b = b[: m * k]
b.sort(key=takeFirst)
print(sum([x[1] for x in b]))
print(" ".join(map(str, [x[0] for x in b][m::m])))
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
def func(n):
return n[1]
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = [[a[i], i] for i in range(len(a))]
b.sort(reverse=True)
b = b[: m * k]
b.sort(key=func)
ans = []
ans2 = 0
for i in range(0, len(b), 1):
if (i + 1) % m == 0:
ans.append(b[i][1] + 1)
ans2 += b[i][0]
print(ans2)
print(" ".join(map(str, ans[:-1])))
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = map(int, input().split())
a = sorted(
[(el[1], el[0]) for el in enumerate(map(int, input().split()))], reverse=True
)
value = 0
ind = [0] * (m * k)
for i in range(m * k):
value += a[i][0]
ind[i] = a[i][1]
ind.sort()
print(value)
for i in range(m, m * k, m):
print(ind[i - 1] + 1, end=" ")
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER STRING
|
An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\ldots$, $a_r$ for some $l, r$.
Suppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.
For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.
You are given an array $a_1, a_2, \ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:
Each element from $a$ belongs to exactly one subarray.
Each subarray has at least $m$ elements.
The sum of all beauties of $k$ subarrays is maximum possible.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m$, $2 \le k$, $m \cdot k \le n$)Β β the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print $k-1$ integers $p_1, p_2, \ldots, p_{k-1}$ ($1 \le p_1 < p_2 < \ldots < p_{k-1} < n$) representing the partition of the array, in which:
All elements with indices from $1$ to $p_1$ belong to the first subarray.
All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.
$\ldots$.
All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.
If there are several optimal partitions, print any of them.
-----Examples-----
Input
9 2 3
5 2 5 2 4 1 1 3 2
Output
21
3 5
Input
6 1 4
4 1 3 2 2 3
Output
12
1 3 5
Input
2 1 2
-1000000000 1000000000
Output
0
1
-----Note-----
In the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.
The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$.
The sum of their beauties is $10 + 6 + 5 = 21$.
In the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$.
|
n, m, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
brr = []
for i in arr:
brr.append(i)
arr.sort(reverse=True)
suma = 0
dic = {}
for i in arr:
dic[i] = 0
for i in range(m * k):
suma += arr[i]
dic[arr[i]] += 1
ans = []
count = 0
counta = 0
for i in range(len(arr)):
if count >= k - 1:
break
if dic[brr[i]] > 0:
dic[brr[i]] -= 1
counta += 1
if counta == m:
ans.append(i + 1)
count += 1
counta = 0
print(suma)
print(*ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.