message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input
The first line of input contains two integer numbers n and k (1 β€ n, k β€ 100) β the number of buckets and the length of the garden, respectively.
The second line of input contains n integer numbers ai (1 β€ ai β€ 100) β the length of the segment that can be watered by the i-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output
Print one integer number β the minimum number of hours required to water the garden.
Examples
Input
3 6
2 3 5
Output
2
Input
6 7
1 2 3 4 5 6
Output
7
Note
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | instruction | 0 | 86,252 | 14 | 172,504 |
Tags: implementation
Correct Solution:
```
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
print(min([k//a for a in arr if k % a == 0]))
``` | output | 1 | 86,252 | 14 | 172,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input
The first line of input contains two integer numbers n and k (1 β€ n, k β€ 100) β the number of buckets and the length of the garden, respectively.
The second line of input contains n integer numbers ai (1 β€ ai β€ 100) β the length of the segment that can be watered by the i-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output
Print one integer number β the minimum number of hours required to water the garden.
Examples
Input
3 6
2 3 5
Output
2
Input
6 7
1 2 3 4 5 6
Output
7
Note
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | instruction | 0 | 86,253 | 14 | 172,506 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
Ans = 100
for i in range(n) :
if k % a[i] == 0 :
Ans = min(Ans, k // a[i])
print(Ans)
``` | output | 1 | 86,253 | 14 | 172,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input
The first line of input contains two integer numbers n and k (1 β€ n, k β€ 100) β the number of buckets and the length of the garden, respectively.
The second line of input contains n integer numbers ai (1 β€ ai β€ 100) β the length of the segment that can be watered by the i-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output
Print one integer number β the minimum number of hours required to water the garden.
Examples
Input
3 6
2 3 5
Output
2
Input
6 7
1 2 3 4 5 6
Output
7
Note
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | instruction | 0 | 86,254 | 14 | 172,508 |
Tags: implementation
Correct Solution:
```
n_buckets, garden_len = map(int, input().split())
buckets = list(map(int, input().split()))
choice = max(b for b in buckets if garden_len % b == 0)
print(garden_len // choice)
``` | output | 1 | 86,254 | 14 | 172,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,920 | 14 | 173,840 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
t = [[i] for i in p]
for i in range(1, n):
t += [t[-1] + i for i in t[: n - i]]
print('\n'.join(str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[: k]))
# Made By Mostafa_Khaled
``` | output | 1 | 86,920 | 14 | 173,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,921 | 14 | 173,842 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
l = sorted(map(int, input().split()), reverse=True)
c = 0
for i in range(n):
for x in l[i:]:
if c == k:
exit()
c += 1
print(i + 1, end=" ")
for y in l[:i]:
print(y, end=" ")
print(x, end=" ")
print()
``` | output | 1 | 86,921 | 14 | 173,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,922 | 14 | 173,844 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
soldiers = list(map(int, input().split()))
count = 0
seen = { 0: 0 }
while count != k:
for beauty, bits in list(seen.items()):
for i, x in enumerate(soldiers):
if (bits&(1 << i)) != 0 or beauty+x in seen:
continue
new_bits = (bits|(1 << i))
seen[beauty+x] = new_bits
#print('%d + %d = %d' % (beauty, x, beauty+x))
group = []
for j, y in enumerate(soldiers):
if (new_bits&(1 << j)) != 0:
group.append(y)
print(' '.join(map(str, [len(group)]+group)))
count += 1
if count == k:
break
if count == k:
break
``` | output | 1 | 86,922 | 14 | 173,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,923 | 14 | 173,846 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
t = [[i] for i in p]
for i in range(1, n):
t += [t[-1] + i for i in t[: n - i]]
print('\n'.join(str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[: k]))
``` | output | 1 | 86,923 | 14 | 173,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,924 | 14 | 173,848 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
soldiers = list(map(int, input().split()))
count = 0
seen = { 0: 0 }
beauties = [ 0 ]
while count != k:
for beauty in beauties:
bits = seen[beauty]
for i, x in enumerate(soldiers):
if (bits&(1 << i)) != 0 or beauty+x in seen:
continue
new_bits = (bits|(1 << i))
seen[beauty+x] = new_bits
beauties.append(beauty+x)
group = []
for j, y in enumerate(soldiers):
if (new_bits&(1 << j)) != 0:
group.append(y)
print(' '.join(map(str, [len(group)]+group)))
count += 1
if count == k:
break
if count == k:
break
``` | output | 1 | 86,924 | 14 | 173,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,925 | 14 | 173,850 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import random
def S(L):
Ans=[]
s=0
for item in L:
s+=item
Ans.append(s)
return Ans
n,k=map(int,input().split())
B=list(map(int,input().split()))
Sums=[]
s=0
for i in range(n):
s+=B[i]
Sums.append(s)
if(k<=n):
for i in range(k):
print(i+1,end="")
for j in range(i+1):
print(" "+str(B[j]),end="")
print()
else:
Ans=[]
length=1
Taken={}
Sums=S(B)
while(len(Ans)<k):
if(length>n):
length=1
random.shuffle(B)
Sums=S(B)
for i in range(n):
if(i+length-1>=n):
break
x=Sums[i+length-1]-Sums[i]+B[i]
if(x in Taken):
continue
Taken[x]=True
L=[length]
done=True
for j in range(i,i+length):
if(B[j] in L[1:]):
done=False
break
L.append(B[j])
if(done):
Ans.append(list(L))
length+=1
for i in range(k):
item=Ans[i]
print(item[0],end="")
for z in range(1,len(item)):
print(" "+str(item[z]),end="")
print()
``` | output | 1 | 86,925 | 14 | 173,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,926 | 14 | 173,852 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
from collections import *
import sys
input=sys.stdin.readline
# "". join(strings)
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def getKthBit(n, k):
return (n & (1 << (k - 1))) >> (k - 1)
n, K = rl()
aa = rl()
aa.sort()
for i in range(n + 1):
if K == 0:
break
smalls = aa[:n - i]
bigs = aa[n-i:]
# if bigs:
# print(len(bigs), " ".join([str(x) for x in bigs]))
# K -= 1
for small in smalls:
print(len(bigs) + 1, " ".join([str(x) for x in bigs]), small)
K -= 1
if K == 0:
break
``` | output | 1 | 86,926 | 14 | 173,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 | instruction | 0 | 86,927 | 14 | 173,854 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
n,k=value()
a=sorted(array())
ma=set()
setNo=1
while(True):
t=ma
for i in a:
if(k<setNo):exit()
if(i not in t):
print(len(ma)+1,*ma,i)
setNo+=1
key=-1
for i in a:
if(i not in ma):
key=max(key,i)
ma.add(key)
``` | output | 1 | 86,927 | 14 | 173,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
from sys import stdin
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return list(stdin.readline()[:-1])
n, k = arr_inp(1)
c = sorted(arr_inp(1))[::-1]
for i in range(min(n, k)):
print(1, c[i])
k -= 1
tem = []
for i in range(min(n - 1, k)):
tem.append(c[i])
for j in range(n - 1, i, -1):
print(i + 2, end=' ')
print(*(tem + [c[j]]))
k -= 1
if not k:
exit()
``` | instruction | 0 | 86,928 | 14 | 173,856 |
Yes | output | 1 | 86,928 | 14 | 173,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
C=[]
U=len(A)
c=0
g=0
for i in range(k):
print(len(C+[A[g]]),' '.join(map(str,C+[A[g]])))
g+=1
if g==len(A):
g=0
C.append(max(A))
A.remove(max(A))
``` | instruction | 0 | 86,929 | 14 | 173,858 |
Yes | output | 1 | 86,929 | 14 | 173,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
def debug(*var, sep = ' ', end = '\n'):
print(*var, file=sys.stderr, end = end, sep = sep)
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
n, k = I()
a = I()
a.sort(reverse = 1)
p = [0] * (n + 1)
for i in range(1, n + 1):
p[i] += p[i - 1] + a[i - 1]
s = set()
window = 1
ans = []
while k and window <= n:
for i in range(window, n + 1):
print(window, *ans, a[i - 1])
k -= 1
if not k:
break
ans.append(a[window - 1])
window += 1
``` | instruction | 0 | 86,930 | 14 | 173,860 |
Yes | output | 1 | 86,930 | 14 | 173,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
j=0
c=0
for i in range(k):
b=[a[i-c]]
for l in range(n-j,n):
b.append(a[l])
print(j+1,*b)
if i-c==n-j-1:
c+=n-j
j+=1
``` | instruction | 0 | 86,931 | 14 | 173,862 |
Yes | output | 1 | 86,931 | 14 | 173,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,m =[int(i) for i in input().split()]
arr = sorted([int(i) for i in input().split()])
out = []
for i in range(len(arr)):
for j in range(i,len(arr)):
out.append(arr[i:j+1])
out.append({arr[i],arr[j]})
s = set()
for i in out:
if sum(i) in s:
continue
else:
s.add(sum(i))
m-=1
print(len(i),*i)
if m==0:
break
``` | instruction | 0 | 86,932 | 14 | 173,864 |
No | output | 1 | 86,932 | 14 | 173,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,m =[int(i) for i in input().split()]
arr = sorted([int(i) for i in input().split()])
out = []
for i in range(len(arr)):
for j in range(i,len(arr)):
out.append(arr[i:j+1])
for i in range(m):
print(len(out[i]),*out[i])
``` | instruction | 0 | 86,933 | 14 | 173,866 |
No | output | 1 | 86,933 | 14 | 173,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
from itertools import combinations
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n + 1):
if cnt == m:
exit(0)
f = list(combinations(a, i))
for j in range(len(f)):
if cnt == m:
exit(0)
cnt += 1
print(i, end=' ')
for k in range(len(f[j])):
print(f[j][k], end=' ')
print()
``` | instruction | 0 | 86,934 | 14 | 173,868 |
No | output | 1 | 86,934 | 14 | 173,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
# import itertools
# import bisect
# import heapq
# import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(10 ** 5)
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
slmii = lambda: sorted(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b): return (a * b) // gcd(a, b)
def main():
# for _ in " " * int(input()):
n, k = mii()
a = lmii()
d = defaultdict(int)
cnt = 0
for i in range(0,2 ** n,2):
sm = 0
lst = []
ln = 0
for j in range(n):
if i & (1 << j):
lst.append(a[n - j - 1])
sm += a[n - j - 1]
ln += 1
if not d[sm] and lst != []:
d[sm] = 1
print(ln, *lst)
cnt += 1
if cnt == k:
break
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 86,935 | 14 | 173,870 |
No | output | 1 | 86,935 | 14 | 173,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,148 | 14 | 174,296 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
def ler():
return [int(x) for x in input().split()]
def dfs(u, adj, visited, s, Pesos, Belezas):
visited[u] = True
total_p = Pesos[u]
total_b = Belezas[u]
s.append(u)
for v in adj[u]:
if not visited[v]:
w, b = dfs(v, adj, visited, s, Pesos, Belezas)
total_p += w
total_b += b
return total_p, total_b
n, m, w = ler()
Pesos = ler()
Belezas = ler()
adj = [[] for _ in range(n)]
for _ in range(m):
x, y = ler()
x -= 1
y -= 1
adj[x].append(y)
adj[y].append(x)
visited = [False] * n
f = [0] * (w + 1)
for i in range(n):
if visited[i]:
continue
s = []
total_p, total_b = dfs(i, adj, visited, s, Pesos, Belezas)
for j in range(w, -1, -1):
jw = j + total_p
if jw <= w:
f[jw] = max(f[jw], f[j] + total_b)
for v in s:
jw = j + Pesos[v]
if jw <= w:
f[jw] = max(f[jw], f[j] + Belezas[v])
print(f[w])
``` | output | 1 | 87,148 | 14 | 174,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,149 | 14 | 174,298 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
from collections import defaultdict
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
group_members = defaultdict(list)
for member in range(self.n):
group_members[self.find(member)].append(member)
return group_members
n,m,w=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
uf=UnionFind(n)
for _ in range(m):
x,y=map(int,input().split())
uf.union(x-1,y-1)
l=uf.roots()
ll=len(l)
dp=[[-10**18]*(w+1) for i in range(ll)]
ca,cb=0,0
dp[0][0]=0
for x in uf.members(l[0]):
if a[x]<=w:
dp[0][a[x]]=max(dp[0][a[x]],b[x])
ca+=a[x]
cb+=b[x]
if ca<=w:
dp[0][ca]=max(dp[0][ca],cb)
for i in range(1,ll):
ca,cb=0,0
for x in uf.members(l[i]):
for j in range(w+1):
dp[i][j]=max(dp[i][j],dp[i-1][j])
if j-a[x]>=0:
dp[i][j]=max(dp[i][j],dp[i-1][j-a[x]]+b[x])
ca+=a[x]
cb+=b[x]
for j in range(w+1):
if j-ca>=0:
dp[i][j]=max(dp[i][j],dp[i-1][j],dp[i-1][j-ca]+cb)
ans=0
for j in range(w+1):
ans=max(ans,dp[ll-1][j])
print(ans)
``` | output | 1 | 87,149 | 14 | 174,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,150 | 14 | 174,300 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
f = lambda: map(int, input().split())
n, m, w = f()
wb = [(0, 0)] + list(zip(f(), f()))
t = list(range(n + 1))
def g(x):
if x == t[x]: return x
t[x] = g(t[x])
return t[x]
for i in range(m):
x, y = f()
x, y = g(x), g(y)
if x != y: t[y] = x
p = [[] for j in range(n + 1)]
for i in range(1, n + 1): p[g(i)].append(i)
d = [1] + [0] * w
for q in p:
if len(q) > 1:
WB = [wb[i] for i in q]
SW = sum(q[0] for q in WB)
SB = sum(q[1] for q in WB)
for D in range(w, -1, -1):
if d[D]:
if D + SW <= w: d[D + SW] = max(d[D + SW], d[D] + SB)
for W, B in WB:
if D + W <= w: d[D + W] = max(d[D + W], d[D] + B)
elif len(q) == 1:
W, B = wb[q[0]]
for D in range(w - W, -1, -1):
if d[D]: d[D + W] = max(d[D + W], d[D] + B)
print(max(d) - 1)
# Made By Mostafa_Khaled
``` | output | 1 | 87,150 | 14 | 174,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,151 | 14 | 174,302 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
n, m, o = map(int, input().split())
wn = map(int, input().split())
bn = map(int, input().split())
wb = [(0, 0)] + list(zip(wn, bn))
l = list(range(n + 1))
def f(x):
if x == l[x]:
return x
l[x] = f(l[x])
return l[x]
for i in range(m):
x, y = map(int, input().split())
x, y = f(x), f(y)
if x != y:
l[y] = x
p = [[] for j in range(n + 1)]
for i in range(1, n + 1):
p[f(i)].append(i)
r = (o+1) * [0]
r[0] = 1
for i in p:
if len(i) > 1:
l = [wb[x] for x in i]
x0 = sum(x[0] for x in l)
x1 = sum(x[1] for x in l)
l.append((x0, x1))
l.sort()
for j in range(o, -1, -1):
if r[j]:
for w, b in l:
if j + w > o:
break
r[j + w] = max(r[j + w], r[j] + b)
elif len(i) == 1:
w, b = wb[i[0]]
for j in range(o - w, -1, -1):
if r[j]:
r[j + w] = max(r[j + w], r[j] + b)
res = max(r) - 1
print(res)
``` | output | 1 | 87,151 | 14 | 174,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,152 | 14 | 174,304 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
def g(x):
if x == t[x]: return x
t[x] = g(t[x])
return t[x]
f = lambda: map(int, input().split())
hoses, pairOfFriends, weight = f()
weightsAndBeauties = [(0, 0)] + list(zip(f(), f()))
t = list(range(hoses + 1))
for i in range(pairOfFriends):
f1, f2 = f()
f1, f2 = g(f1), g(f2)
if f1 != f2:
t[f2] = f1
p = [[] for j in range(hoses + 1)]
for i in range(1, hoses + 1):
p[g(i)].append(i)
beauties = [1] + [0] * weight
for q in p:
if len(q) > 1:
t = [weightsAndBeauties[i] for i in q]
t.append((sum(f1[0] for f1 in t), sum(f1[1] for f1 in t)))
t.sort(key=lambda f1: f1[0])
for j in range(weight, -1, -1):
if beauties[j]:
for w, b in t:
if j + w > weight:
break
else:
beauties[j + w] = max(beauties[j + w], beauties[j] + b)
elif len(q) == 1:
w, b = weightsAndBeauties[q[0]]
for j in range(weight - w, -1, -1):
if beauties[j]:
beauties[j + w] = max(beauties[j + w], beauties[j] + b)
maxBeauty = max(beauties) - 1
print(maxBeauty)
``` | output | 1 | 87,152 | 14 | 174,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,153 | 14 | 174,306 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
n, m, k = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
ab = [(0, 0)] + list(zip(a, b))
l = list(range(n + 1))
def f(x):
if x == l[x]:
return x
l[x] = f(l[x])
return l[x]
for i in range(m):
x, y = map(int, input().split())
x, y = f(x), f(y)
if x != y:
l[y] = x
p = [[] for j in range(n + 1)]
for i in range(1, n + 1):
p[f(i)].append(i)
r = (k+1) * [0]
r[0] = 1
for i in p:
if len(i) > 1:
l = [ab[x] for x in i]
x0 = sum(x[0] for x in l)
x1 = sum(x[1] for x in l)
l.append((x0, x1))
l.sort()
for j in range(k, -1, -1):
if r[j]:
for w, b in l:
if j + w > k:
break
r[j + w] = max(r[j + w], r[j] + b)
elif len(i) == 1:
w, b = ab[i[0]]
for j in range(k - w, -1, -1):
if r[j]:
r[j + w] = max(r[j + w], r[j] + b)
res = max(r) - 1
print(res)
``` | output | 1 | 87,153 | 14 | 174,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,154 | 14 | 174,308 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
R = lambda: map(int, input().split())
n, m, w = R()
ws = [0] + list(R())
bs = [0] + list(R())
g = [[] for x in range(n + 1)]
for i in range(m):
x, y = R()
g[x].append(y)
g[y].append(x)
cs = [0] * (n + 1)
cnt = 1
for i in range(1, n + 1):
if not cs[i]:
cs[i] = cnt
q = []
q.append(i)
while q:
nxt = q.pop()
for x in g[nxt]:
if not cs[x]:
cs[x] = cnt
q.append(x)
cnt += 1
gs = [[] for i in range(cnt)]
for i in range(1, n + 1):
gs[cs[i]].append(i)
dp = [[0] * (w + 1) for i in range(cnt)]
for i in range(1, cnt):
tw = sum(ws[k] for k in gs[i])
tb = sum(bs[k] for k in gs[i])
for j in range(1, w + 1):
dp[i][j] = max(dp[i][j], dp[i - 1][j], (dp[i - 1][j - tw] + tb if j >= tw else 0))
for k in gs[i]:
dp[i][j] = max(dp[i][j], dp[i - 1][j], (dp[i - 1][j - ws[k]] + bs[k] if j >= ws[k] else 0))
print(dp[-1][w])
``` | output | 1 | 87,154 | 14 | 174,309 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7. | instruction | 0 | 87,155 | 14 | 174,310 |
Tags: dfs and similar, dp, dsu
Correct Solution:
```
import math,sys,bisect,heapq,os
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
def input(): return sys.stdin.readline().rstrip('\r\n')
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda: list(map(int, input().split()))
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
def solve():
G = defaultdict(list)
def addEdge(a,b):
G[a].append(b)
G[b].append(a)
def dfs(node):
d = deque()
d.append(node)
vis[node] = True
T = []
S = []
tot = 0;wt = 0
while d:
x = d.pop()
S.append(B[x-1])
T.append(W[x-1])
# tot += B[x-1]
# wt += W[x-1]
for i in G.get(x,[]):
if not vis[i]:
vis[i] = True
d.append(i)
# if len(S) > 1:
# S.append(tot)
# T.append(wt)
return S,T
n,m,w =aj()
W = aj()
B = aj()
vis = [False]*(n+1)
for i in range(m):
u,v = aj()
addEdge(u,v)
A1 = []
A2 = []
Id = 1
for i in range(1,n+1):
if not vis[i]:
c,d = dfs(i)
A1.append(c)
A2.append(d)
# print(A1)
# print(A2)
# print(w)
# dp = {}
# def fun(pos = 0,wt = 0):
# if wt > w:
# return -float('inf')
# if pos >= len(A1):
# return 0
# z = dp.get((pos,wt),-1)
# if z!= -1:
# return z
# ans = 0
# c2 = 0
# for i in range(len(A1[pos])):
# c2 = max(c2,A1[pos][i] + fun(pos+1,wt + A2[pos][i]))
# c3 = fun(pos + 1,wt)
# z = max(c2,c3)
# dp[(pos,wt)] = z
# return z
dp = [[0]*(w+1) for i in range(len(A1)+1)]
for i in range(len(A1)):
weight_sum = sum(x for x in A2[i])
beauty_sum = sum(x for x in A1[i])
for j in range(w + 1):
dp[i][j] = max(beauty_sum + dp[i - 1][j - weight_sum]
if weight_sum <= j else 0, dp[i - 1][j])
for k in range(len(A1[i])):
dp[i][j] = max(dp[i][j], (dp[i - 1][j - A2[i][k]] +
A1[i][k] if A2[i][k] <= j else 0))
# print(fun())
print(dp[len(A1)-1][w])
try:
#os.system("online_judge.py")
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
solve()
``` | output | 1 | 87,155 | 14 | 174,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
from sys import stdin, stdout
from collections import defaultdict as dd
read, write = stdin.readline, stdout.write
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b):
a, b = self.find(a), self.find(b)
if a != b:
if self.size[a] < self.size[b]:
a, b = b, a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
n, m, w = map(int, read().split())
weights = list(map(int, read().split()))
beauties = list(map(int, read().split()))
DSU = DisjointSetUnion(n)
for _ in range(m):
h1, h2 = map(int, read().split())
DSU.union(h1-1, h2-1)
groups = dd(list)
for i in range(n): DSU.find(i)
for hose, parent in enumerate(DSU.parent): groups[parent].append(hose)
dp = [0]*(w+1)
for friends in groups.values():
dp_aux = dp[:]
group_weight = group_beauty = 0
for friend in friends:
f_weight, f_beauty = weights[friend], beauties[friend]
group_weight += f_weight; group_beauty += f_beauty
for weight in range(f_weight, w+1):
dp[weight] = max(dp[weight], dp_aux[weight - f_weight] + f_beauty)
for weight in range(group_weight, w+1):
dp[weight] = max(dp[weight], dp_aux[weight - group_weight] + group_beauty)
print(dp[-1])
``` | instruction | 0 | 87,156 | 14 | 174,312 |
Yes | output | 1 | 87,156 | 14 | 174,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
hoses, pairs, total_weight = map(int, input().split())
weight_arr = list(map(int, input().split()))
beauty_arr = list(map(int, input().split()))
arr = [-1] * hoses
def get(hose):
if arr[hose] < 0:
return hose
arr[hose] = get(arr[hose])
return arr[hose]
def join(left, right):
left, right = get(left), get(right)
if left != right:
arr[left] = right
for i in range(pairs):
left, right = map(int, input().split())
join(left - 1, right - 1)
groups = [list() for i in range(hoses)]
for i in range(hoses):
groups[get(i)].append(i)
groups = [group for group in groups if group]
dp = [[0] * (total_weight + 1) for i in range(len(groups) + 1)]
for i in range(len(groups)):
weight_sum = sum(weight_arr[x] for x in groups[i])
beauty_sum = sum(beauty_arr[x] for x in groups[i])
for j in range(total_weight + 1):
dp[i][j] = max(beauty_sum + dp[i - 1][j - weight_sum]
if weight_sum <= j else 0, dp[i - 1][j])
for k in groups[i]:
dp[i][j] = max(dp[i][j], (dp[i - 1][j - weight_arr[k]] +
beauty_arr[k] if weight_arr[k] <= j else 0))
print(dp[len(groups) - 1][total_weight])
``` | instruction | 0 | 87,157 | 14 | 174,314 |
Yes | output | 1 | 87,157 | 14 | 174,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
n, m, wn = map(int, input().split())
Wi = [(0, 0)] + list(zip(map(int, input().split()), map(int, input().split())))
listaux3 = list(range(n + 1))
def aux(x):
if x == listaux3[x]:
return x
listaux3[x] = aux(listaux3[x])
return listaux3[x]
for i in range(m):
x, y = map(int, input().split())
x, y = aux(x), aux(y)
if x != y:
listaux3[y] = x
listaux1 = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
listaux1[aux(i)].append(i)
listaux2 = [1] + [0] * wn
for k in listaux1:
if len(k) > 1:
listaux3 = [Wi[i] for i in k]
listaux3.append((sum(x[0] for x in listaux3), sum(x[1] for x in listaux3)))
listaux3.sort(key=lambda x: x[0])
for j in range(wn, -1, -1):
if listaux2[j]:
for w, b in listaux3:
if j + w > wn:
break
listaux2[j + w] = max(listaux2[j + w], listaux2[j] + b)
elif len(k) == 1:
w, b = Wi[k[0]]
for j in range(wn - w, -1, -1):
if listaux2[j]:
listaux2[j + w] = max(listaux2[j + w], listaux2[j] + b)
print(max(listaux2) - 1)
``` | instruction | 0 | 87,158 | 14 | 174,316 |
Yes | output | 1 | 87,158 | 14 | 174,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
class disjoint:
def __init__(self,n):
self.rank=[1]*n
self.parent=[i for i in range(n)]
def find(self,x):
if(self.parent[x]!=x):
self.parent[x]=self.find(self.parent[x])
return self.parent[x];
def union(self,x,y):
xid=self.find(x)
yid=self.find(y)
if(xid==yid):
return;
if(self.rank[xid]<self.rank[yid]):
self.parent[xid]=yid
return;
elif(self.rank[xid]>self.rank[yid]):
self.parent[yid]=xid # merging y into x
return;
else:
self.parent[yid]=xid
self.rank[xid]+=1
return;
import sys
input=sys.stdin.readline
n,m,w=map(int,input().split())
obj=disjoint(n)
z=list(map(int,input().split()))
be=list(map(int,input().split()))
ans=[]
for i in range(len(z)):
ans.append([i,z[i],be[i]])
for i in range(m):
p,q=map(int,input().split())
obj.union(p-1,q-1)
from collections import *
al=defaultdict(list)
for i in range(len(ans)):
y=obj.find(ans[i][0])
al[y].append(ans[i][0])
dp=[[0 for i in range(len(al)+1)] for i in range(w+1)]
c1=0
maxa=0
for i in al:
if(c1==0):
q=al[i]
total=0
bea=0
for x in q:
wei=ans[x][1]
if(wei<=w):
dp[wei][c1]=max(dp[wei][c1],ans[x][2])
maxa=max(maxa,dp[wei][c1])
total+=wei
bea+=ans[x][2]
if(total<=w):
dp[total][c1]=max(dp[total][c1],bea)
maxa=max(maxa,dp[total][c1])
c1+=1
else:
q=al[i]
total=0
dil=0
bea=0
wei=0
for x in q:
wei=ans[x][1]
bea=ans[x][2]
total+=wei
dil+=bea
for j in range(w+1):
if(wei>j):
dp[j][c1]=max(dp[j][c1-1],dp[j][c1])
maxa=max(maxa,dp[j][c1])
continue;
else:
dp[j][c1]=max(dp[j][c1],dp[j-wei][c1-1]+bea,dp[j][c1-1])
maxa=max(maxa,dp[j][c1])
if(total<=w):
dp[total][c1]=max(dp[total][c1-1],dil,dp[total][c1])
maxa=max(maxa,dp[total][c1])
for j in range(w+1):
if(j<=total):
continue;
else:
dp[j][c1]=max(dp[j][c1],dil+dp[j-total][c1-1])
maxa=max(maxa,dp[j][c1])
c1+=1
print(maxa)
``` | instruction | 0 | 87,159 | 14 | 174,318 |
Yes | output | 1 | 87,159 | 14 | 174,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
class disjoint:
def __init__(self,n):
self.rank=[1]*n
self.parent=[i for i in range(n)]
def find(self,x):
if(self.parent[x]!=x):
self.parent[x]=self.find(self.parent[x])
return self.parent[x];
def union(self,x,y):
xid=self.find(x)
yid=self.find(y)
if(xid==yid):
return;
if(self.rank[xid]<self.rank[yid]):
self.parent[xid]=yid
return;
elif(self.rank[xid]>self.rank[yid]):
self.parent[yid]=xid # merging y into x
return;
else:
self.parent[yid]=xid
self.rank[xid]+=1
return;
import sys
input=sys.stdin.readline
n,m,w=map(int,input().split())
obj=disjoint(n)
z=list(map(int,input().split()))
be=list(map(int,input().split()))
ans=[]
for i in range(len(z)):
ans.append([i,z[i],be[i]])
for i in range(m):
p,q=map(int,input().split())
obj.union(p-1,q-1)
from collections import *
al=defaultdict(list)
for i in range(len(ans)):
y=obj.find(ans[i][0])
al[y].append(ans[i][0])
dp=[[0 for i in range(len(al)+1)] for i in range(w+1)]
c1=0
for i in al:
if(c1==0):
q=al[i]
total=0
bea=0
for x in q:
wei=ans[x][1]
if(wei<=w):
dp[wei][c1]=max(dp[wei][c1],ans[x][2])
total+=wei
bea+=ans[x][2]
if(total<=w):
dp[total][c1]=max(dp[total][c1],bea)
c1+=1
else:
for j in range(w+1):
dp[j][c1]=max(dp[j][c1],dp[j][c1-1])
q=al[i]
total=0
dil=0
bea=0
wei=0
for x in q:
wei=ans[x][1]
bea=ans[x][2]
total+=wei
dil+=bea
for j in range(w+1):
if(wei>j):
dp[j][c1]=max(dp[j][c1-1],dp[j][c1])
continue;
else:
dp[j][c1]=max(dp[j][c1],dp[j-wei][c1-1]+bea,dp[j][c1-1])
if(total<=w):
dp[total][c1]=max(dp[total][c1-1],dil,dp[total][c1])
c1+=1
maxa=0
for j in range(w+1):
maxa=max(maxa,dp[j][c1-1])
print(maxa)
``` | instruction | 0 | 87,160 | 14 | 174,320 |
No | output | 1 | 87,160 | 14 | 174,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
import math,sys,bisect,heapq,os
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
def input(): return sys.stdin.readline().rstrip('\r\n')
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda: list(map(int, input().split()))
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
def solve():
G = defaultdict(list)
def addEdge(a,b):
G[a].append(b)
G[b].append(a)
def dfs(node):
d = deque()
d.append(node)
vis[node] = True
T = []
S = []
tot = 0;wt = 0
while d:
x = d.pop()
S.append(B[x-1])
T.append(W[x-1])
# tot += B[x-1]
# wt += W[x-1]
for i in G.get(x,[]):
if not vis[i]:
vis[i] = True
d.append(i)
# if len(S) > 1:
# S.append(tot)
# T.append(wt)
return S,T
n,m,w =aj()
W = aj()
B = aj()
vis = [False]*(n+1)
for i in range(m):
u,v = aj()
addEdge(u,v)
A1 = []
A2 = []
Id = 1
for i in range(1,n+1):
if not vis[i]:
c,d = dfs(i)
A1.append(c)
A2.append(d)
# print(A1)
# print(A2)
# print(w)
# dp = {}
# def fun(pos = 0,wt = 0):
# if wt > w:
# return -float('inf')
# if pos >= len(A1):
# return 0
# z = dp.get((pos,wt),-1)
# if z!= -1:
# return z
# ans = 0
# c2 = 0
# for i in range(len(A1[pos])):
# c2 = max(c2,A1[pos][i] + fun(pos+1,wt + A2[pos][i]))
# c3 = fun(pos + 1,wt)
# z = max(c2,c3)
# dp[(pos,wt)] = z
# return z
dp = [[0]*(w+1) for i in range(len(A1)+1)]
for i in range(len(A1)):
weight_sum = sum(x for x in A1[i])
beauty_sum = sum(x for x in A1[i])
for j in range(w + 1):
dp[i][j] = max(beauty_sum + dp[i - 1][j - weight_sum]
if weight_sum <= j else 0, dp[i - 1][j])
for k in range(len(A1[i])):
dp[i][j] = max(dp[i][j], (dp[i - 1][j - A2[i][k]] +
A1[i][k] if A2[i][k] <= j else 0))
# print(fun())
print(dp[len(A1)-1][w])
try:
#os.system("online_judge.py")
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
solve()
``` | instruction | 0 | 87,161 | 14 | 174,322 |
No | output | 1 | 87,161 | 14 | 174,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
from collections import defaultdict
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
group_members = defaultdict(list)
for member in range(self.n):
group_members[self.find(member)].append(member)
return group_members
n,m,w=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
uf=UnionFind(n)
for _ in range(m):
x,y=map(int,input().split())
uf.union(x-1,y-1)
l=uf.roots()
ll=len(l)
dp=[[0]*(w+1) for i in range(ll)]
ca,cb=0,0
for x in uf.members(l[0]):
if a[x]<=w:
dp[0][a[x]]=max(dp[0][a[x]],b[x])
ca+=a[x]
cb+=b[x]
if ca<=w:
dp[0][ca]=max(dp[0][ca],cb)
for i in range(1,ll):
ca,cb=0,0
for x in uf.members(l[i]):
for j in range(w+1):
if j-a[x]>=0:
dp[i][j]=max(dp[i][j],dp[i-1][j],dp[i-1][j-a[x]]+b[x])
ca+=a[x]
cb+=b[x]
for j in range(w+1):
if j-ca>=0:
dp[i][j]=max(dp[i-1][j],dp[i-1][j-ca]+cb)
ans=0
for j in range(w+1):
ans=max(ans,dp[ll-1][j])
print(ans)
``` | instruction | 0 | 87,162 | 14 | 174,324 |
No | output | 1 | 87,162 | 14 | 174,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 β€ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 β€ n β€ 1000, <image>, 1 β€ w β€ 1000) β the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 β€ wi β€ 1000) β the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 β€ bi β€ 106) β the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 β€ xi, yi β€ n, xi β yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Submitted Solution:
```
f = lambda: map(int, input().split())
n, m, w = f()
wb = [(0, 0)] + list(zip(f(), f()))
t = list(range(n + 1))
def g(x):
if x == t[x]: return x
t[x] = g(t[x])
return t[x]
for i in range(m):
x, y = f()
x, y = g(x), g(y)
if x != y: t[y] = x
p = [[] for j in range(n + 1)]
for i in range(1, n + 1): p[g(i)].append(i)
d = [1] + [0] * w
for q in p:
if len(q) < 2: continue
WB = [wb[i] for i in q]
W = sum(q[0] for q in WB)
B = sum(q[1] for q in WB)
for D in range(w - W, -1, -1):
if d[D]: d[D + W] = max(d[D + W], d[D] + B)
for W, B in WB:
for D in range(w - W, -1, -1):
if d[D]: d[D + W] = max(d[D + W], d[D] + B)
for q in p:
if len(q) != 1: continue
W, B = wb[q[0]]
for D in range(w - W, -1, -1):
if d[D]: d[D + W] = max(d[D + W], d[D] + B)
print(max(d) - 1)
``` | instruction | 0 | 87,163 | 14 | 174,326 |
No | output | 1 | 87,163 | 14 | 174,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should also be tasty, so the glass can contain only integer number of liters of each Coke type (some types can be not presented in the glass). Also, they want to minimize the total volume of Coke in the glass.
Carbon dioxide concentration is defined as the volume of carbone dioxide in the Coke divided by the total volume of Coke. When you mix two Cokes, the volume of carbon dioxide sums up, and the total volume of Coke sums up as well.
Help them, find the minimal natural number of liters needed to create a glass with carbon dioxide concentration <image>. Assume that the friends have unlimited amount of each Coke type.
Input
The first line contains two integers n, k (0 β€ n β€ 1000, 1 β€ k β€ 106) β carbon dioxide concentration the friends want and the number of Coke types.
The second line contains k integers a1, a2, ..., ak (0 β€ ai β€ 1000) β carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.
Output
Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration <image>, or -1 if it is impossible.
Examples
Input
400 4
100 300 450 500
Output
2
Input
50 2
100 25
Output
3
Note
In the first sample case, we can achieve concentration <image> using one liter of Coke of types <image> and <image>: <image>.
In the second case, we can achieve concentration <image> using two liters of <image> type and one liter of <image> type: <image>. | instruction | 0 | 87,182 | 14 | 174,364 |
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
##
##
##
import sys
def line():
return sys.stdin.readline()
def numbers():
return list(map(int, line().split()))
def number():
return int(line())
adjlist = {}
n, k = 0, 0
mark = [False]*2010
edges = [False]*1010
# bfs for "ssph"
def bfs(s):
i = 0
frontier = [s]
while frontier:
if mark[s]:
break;
next_frontier = []
for u in frontier:
# check next state
for v, isState in enumerate(edges):
if isState:
# check new node
state = u + (n - 1000) - v
if state >= 0 and state <= 2000 and not mark[state]:
mark[state] = True
next_frontier.append(state)
frontier = next_frontier
i += 1
if mark[s]:
return i
else:
return -1
# main program
[n, k] = numbers()
concentrations = numbers()
# reading edges
for x in concentrations:
edges[x] = True
n = n + 1000
ans = bfs(1000)
print(ans)
# 1496438704903
# Made By Mostafa_Khaled
``` | output | 1 | 87,182 | 14 | 174,365 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should also be tasty, so the glass can contain only integer number of liters of each Coke type (some types can be not presented in the glass). Also, they want to minimize the total volume of Coke in the glass.
Carbon dioxide concentration is defined as the volume of carbone dioxide in the Coke divided by the total volume of Coke. When you mix two Cokes, the volume of carbon dioxide sums up, and the total volume of Coke sums up as well.
Help them, find the minimal natural number of liters needed to create a glass with carbon dioxide concentration <image>. Assume that the friends have unlimited amount of each Coke type.
Input
The first line contains two integers n, k (0 β€ n β€ 1000, 1 β€ k β€ 106) β carbon dioxide concentration the friends want and the number of Coke types.
The second line contains k integers a1, a2, ..., ak (0 β€ ai β€ 1000) β carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.
Output
Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration <image>, or -1 if it is impossible.
Examples
Input
400 4
100 300 450 500
Output
2
Input
50 2
100 25
Output
3
Note
In the first sample case, we can achieve concentration <image> using one liter of Coke of types <image> and <image>: <image>.
In the second case, we can achieve concentration <image> using two liters of <image> type and one liter of <image> type: <image>. | instruction | 0 | 87,184 | 14 | 174,368 |
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
##
##
##
import sys
def line():
return sys.stdin.readline()
def numbers():
return list(map(int, line().split()))
def number():
return int(line())
adjlist = {}
n, k = 0, 0
mark = [False]*2010
edges = [False]*1010
# bfs for "ssph"
def bfs(s):
i = 0
frontier = [s]
while frontier:
if mark[s]:
break;
next_frontier = []
for u in frontier:
# check next state
for v, isState in enumerate(edges):
if isState:
# check new node
state = u + (n - 1000) - v
if state >= 0 and state <= 2000 and not mark[state]:
mark[state] = True
next_frontier.append(state)
frontier = next_frontier
i += 1
if mark[s]:
return i
else:
return -1
# main program
[n, k] = numbers()
concentrations = numbers()
# reading edges
for x in concentrations:
edges[x] = True
n = n + 1000
ans = bfs(1000)
print(ans)
# 1496438704903
``` | output | 1 | 87,184 | 14 | 174,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,244 | 14 | 174,488 |
Tags: binary search, implementation, sortings
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
#sys.setrecursionlimit(300000)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=300006, func=lambda a, b: min(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b:a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <=key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
class TrieNode:
def __init__(self):
self.children = [None] * 26
self.isEndOfWord = False
class Trie:
def __init__(self):
self.root = self.getNode()
def getNode(self):
return TrieNode()
def _charToIndex(self, ch):
return ord(ch) - ord('a')
def insert(self, key):
pCrawl = self.root
length = len(key)
for level in range(length):
index = self._charToIndex(key[level])
if not pCrawl.children[index]:
pCrawl.children[index] = self.getNode()
pCrawl = pCrawl.children[index]
pCrawl.isEndOfWord = True
def search(self, key):
pCrawl = self.root
length = len(key)
for level in range(length):
index = self._charToIndex(key[level])
if not pCrawl.children[index]:
return False
pCrawl = pCrawl.children[index]
return pCrawl != None and pCrawl.isEndOfWord
#-----------------------------------------trie---------------------------------
class Node:
def __init__(self, data):
self.data = data
self.count=0
self.left = None # left node for 0
self.right = None # right node for 1
class BinaryTrie:
def __init__(self):
self.root = Node(0)
def insert(self, pre_xor):
self.temp = self.root
for i in range(31, -1, -1):
val = pre_xor & (1 << i)
if val:
if not self.temp.right:
self.temp.right = Node(0)
self.temp = self.temp.right
self.temp.count+=1
if not val:
if not self.temp.left:
self.temp.left = Node(0)
self.temp = self.temp.left
self.temp.count += 1
self.temp.data = pre_xor
def query(self, xor):
self.temp = self.root
for i in range(31, -1, -1):
val = xor & (1 << i)
if not val:
if self.temp.left and self.temp.left.count>0:
self.temp = self.temp.left
elif self.temp.right:
self.temp = self.temp.right
else:
if self.temp.right and self.temp.right.count>0:
self.temp = self.temp.right
elif self.temp.left:
self.temp = self.temp.left
self.temp.count-=1
return xor ^ self.temp.data
#-------------------------bin trie-------------------------------------------
n,x,y=map(int,input().split())
l=list(map(int,input().split()))
l=[(l[i],i+1) for i in range(n)]
l.sort()
t=1
f=-1
for i in range(n-1,0,-1):
if l[i][0]*t>=x:
f=i
break
t+=1
t=1
f1 = -1
if f!=-1:
for i in range(f-1,-1,-1):
if l[i][0] * t >= y:
f1=i
break
t += 1
if f1!=-1:
q=[]
q1=[]
for i in range(f1,f):
q.append(l[i][1])
for i in range(f,n):
q1.append(l[i][1])
print("Yes")
print(len(q1),len(q))
print(*q1)
print(*q)
sys.exit(0)
t=1
f=-1
for i in range(n-1,0,-1):
if l[i][0]*t>=y:
f=i
break
t+=1
t=1
f1=-1
if f!=-1:
for i in range(f-1,-1,-1):
if l[i][0] * t >= x:
f1=i
break
t += 1
if f1!=-1:
q=[]
q1=[]
for i in range(f1,f):
q.append(l[i][1])
for i in range(f,n):
q1.append(l[i][1])
print("Yes")
print(len(q),len(q1))
print(*q)
print(*q1)
sys.exit(0)
print("No")
``` | output | 1 | 87,244 | 14 | 174,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,245 | 14 | 174,490 |
Tags: binary search, implementation, sortings
Correct Solution:
```
# python3
def readline(): return tuple(map(int, input().split()))
def ceil_div(num, den): return (num - 1) // den + 1
def main():
n, x1, x2 = readline()
c = readline()
xx = (x1, x2)
servers = sorted(enumerate(c, start=1), key=lambda p: p[1])
for (i, a) in enumerate(servers):
for (j, x) in enumerate(xx):
kj = ceil_div(x, a[1])
if i + kj < n and (n - i - kj) * servers[i + kj][1] >= sum(xx) - x:
print("Yes")
l1 = servers[i:i+kj]
l2 = servers[i+kj:]
if j: l1, l2 = l2, l1
print(len(l1), len(l2))
print(" ".join(str(d[0]) for d in l1))
print(" ".join(str(d[0]) for d in l2))
return
print("No")
main()
# Made By Mostafa_Khaled
``` | output | 1 | 87,245 | 14 | 174,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,246 | 14 | 174,492 |
Tags: binary search, implementation, sortings
Correct Solution:
```
n, x1, x2 = map(int, input().split())
c = list(map(int, input().split()))
c = [(ci, i) for i, ci in enumerate(c)]
c.sort(reverse=True)
def check(x1,x2,reverse=False):
sum1 = sum2 = 0
i = i1 = i2 = 0
while i < len(c):
sum1 += c[i][0]
i += 1
if sum1 >= x1 and 1.0*x1/i <= c[i-1][0]: break
i1 = i
if i1 == n: return False
while i < len(c):
sum2 += c[i][0]
i += 1
if sum2 >= x2 and 1.0*x2/(i-i1) <= c[i-1][0]:
print('Yes')
if reverse:
print(i-i1, i1)
print(' '.join(map(str, [ci[1]+1 for ci in c[i1:i]])))
print(' '.join(map(str, [ci[1]+1 for ci in c[:i1]])))
else:
print(i1, i-i1)
print(' '.join(map(str, [ci[1]+1 for ci in c[:i1]])))
print(' '.join(map(str, [ci[1]+1 for ci in c[i1:i]])))
return True
return False
if not (check(x1, x2) or check(x2, x1,reverse=True)):
print('No')
``` | output | 1 | 87,246 | 14 | 174,493 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,247 | 14 | 174,494 |
Tags: binary search, implementation, sortings
Correct Solution:
```
# python3
def readline(): return tuple(map(int, input().split()))
def ceil_div(num, den): return (num - 1) // den + 1
def main():
n, x1, x2 = readline()
c = readline()
xx = (x1, x2)
servers = sorted(enumerate(c, start=1), key=lambda p: p[1])
for (i, a) in enumerate(servers):
for (j, x) in enumerate(xx):
kj = ceil_div(x, a[1])
if i + kj < n and (n - i - kj) * servers[i + kj][1] >= sum(xx) - x:
print("Yes")
l1 = servers[i:i+kj]
l2 = servers[i+kj:]
if j: l1, l2 = l2, l1
print(len(l1), len(l2))
print(" ".join(str(d[0]) for d in l1))
print(" ".join(str(d[0]) for d in l2))
return
print("No")
main()
``` | output | 1 | 87,247 | 14 | 174,495 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,248 | 14 | 174,496 |
Tags: binary search, implementation, sortings
Correct Solution:
```
n, a, b = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
hs = sorted(enumerate(hs), key=lambda x: x[1])
for i in range(1, n+1):
if hs[-i][1] * i >= a:
break
else:
print('No')
exit()
for j in range(i+1, n+1):
if hs[-j][1] * (j - i) >= b:
print('Yes')
print(i, j - i)
print(" ".join(map(str, [index+1 for index,_ in hs[-i:]])))
print(" ".join(map(str, [index+1 for index,_ in hs[-j:-i]])))
break
else:
for i in range(1, n+1):
if hs[-i][1] * i >= b:
break
else:
print('No')
exit()
for j in range(i+1, n+1):
if hs[-j][1] * (j - i) >= a:
print('Yes')
print(j - i, i)
print(" ".join(map(str, [index+1 for index,_ in hs[-j:-i]])))
print(" ".join(map(str, [index+1 for index,_ in hs[-i:]])))
break
else:
print('No')
``` | output | 1 | 87,248 | 14 | 174,497 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,249 | 14 | 174,498 |
Tags: binary search, implementation, sortings
Correct Solution:
```
def fin(c, x):
return (x + c - 1) // c
def ck(x, b):
r = (n, n)
for i in range(b, n):
r = min(r, (i + fin(c[i][0], x), i))
return r
def sol(r, l):
if r[0] <= n and l[0] <= n and r[1] < n and l[1] < n :
print("Yes")
print(r[0] - r[1], l[0]- l[1])
print(' '.join([str(x[1]) for x in c[r[1]:r[0]]]))
print(' '.join([str(x[1]) for x in c[l[1]:l[0]]]))
return True
else:
return False
n, x1, x2 = [int(x) for x in input().split()]
c = sorted([(int(x), i + 1) for i, x in enumerate(input().split())])
r1 = ck(x1, 0)
l1 = ck(x2, r1[0])
r2 = ck(x2, 0)
l2 = ck(x1, r2[0])
if not sol(r1, l1) and not sol(l2, r2):
print("No")
# 6 8 16
# 3 5 2 9 8 7
``` | output | 1 | 87,249 | 14 | 174,499 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units. | instruction | 0 | 87,250 | 14 | 174,500 |
Tags: binary search, implementation, sortings
Correct Solution:
```
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 12/18/18
"""
import collections
import time
import os
import sys
import bisect
import heapq
n, x1, x2 = map(int, input().split())
C = [int(x) for x in input().split()]
C = [(v, i+1) for i, v in enumerate(C)]
C.sort()
def check(x1, x2, rev):
r = n
p1, p2 = [], []
for i in range(n-1, -1, -1):
if C[i][0] * (n-i) >= x1:
r = i
p1 = [v[1] for v in C[i:]]
break
if p1:
for i in range(r, -1, -1):
if C[i][0] * (r-i) >= x2:
p2 = [v[1] for v in C[i: r]]
if rev:
p1, p2 = p2, p1
print('Yes')
print('{} {}'.format(len(p1), len(p2)))
print(' '.join(map(str, p1)))
print(' '.join(map(str, p2)))
exit(0)
check(x1, x2, False)
check(x2, x1, True)
print('No')
``` | output | 1 | 87,250 | 14 | 174,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
n, x1, x2 = map(int, input().split())
c = list(map(int, input().split()))
c = [(ci, i) for i, ci in enumerate(c)]
c.sort(reverse=True)
def check(x1,x2):
sum1 = sum2 = 0
i = i1 = i2 = 0
while i < len(c):
sum1 += c[i][0]
i += 1
if sum1 >= x1: break
i1 = i
while i < len(c):
sum2 += c[i][0]
i += 1
if sum2 >= x2: break
i2 = i
if 1.0*x1/i1 <= c[i1-1][0] and 1.0*x2/(i2-i1) <= c[i2-1][0] :
print('Yes')
print("%d %s"%(i1, ' '.join(map(str, [ci[1]+1 for ci in c[:i1]]))))
print("%d %s"%(i2-i1, ' '.join(map(str, [ci[1]+1 for ci in c[i1:i2]]))))
return True
return False
if not (check(x1, x2) or check(x2, x1)):
print('No')
``` | instruction | 0 | 87,251 | 14 | 174,502 |
No | output | 1 | 87,251 | 14 | 174,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
n, x1, x2 = map(int, input().split())
c = list(map(int, input().split()))
c = [(ci, i) for i, ci in enumerate(c)]
c.sort(reverse=True)
def check(x1,x2):
sum1 = sum2 = 0
i = i1 = i2 = 0
while i < len(c):
sum1 += c[i][0]
i += 1
if sum1 >= x1: break
i1 = i
while i < len(c):
sum2 += c[i][0]
i += 1
if sum2 >= x2: break
i2 = i
if 1.0*x1/i1 <= c[i1-1][0] and 1.0*x2/(i2-i1) <= c[i2-1][0] :
print('Yes')
print(i1, i2-i1)
print(' '.join(map(str, [ci[1]+1 for ci in c[:i1]])))
print(' '.join(map(str, [ci[1]+1 for ci in c[i1:i2]])))
return True
return False
if not (check(x1, x2) or check(x2, x1)):
print('No')
``` | instruction | 0 | 87,252 | 14 | 174,504 |
No | output | 1 | 87,252 | 14 | 174,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
import random
print(['NO','YES'][random.randint(0,1)])
``` | instruction | 0 | 87,253 | 14 | 174,506 |
No | output | 1 | 87,253 | 14 | 174,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
get=lambda:map(int,input().split())
from functools import lru_cache
n,x1,x2=get()
arr=list(get())
s=sum(arr)
if s<x1+x2:
print("No")
cache={}
def f(n,i):
if (n,i) in cache:
return cache[(n,i)]
if n<=0:
cache[(n,i)]=0
return 0
if i<0:
cache[(n,i)]=float('inf')
return float('inf')
ans= min(f(n,i-1),f(n-arr[i],i-1)+arr[i])
cache[(n,i)]=ans
return ans
if s<f(x1,n-1)+x2:
print("No")
else:
print('Yes')
incl=[]
nincl=[]
i=n-1
while x1>=0 and i>=0:
a=cache[(x1,i-1)]
b=cache[(x1-arr[i],i-1)]+arr[i]
if a<=b:
nincl.append(i+1)
else:
incl.append(i+1)
i-=1
print(len(incl),len(nincl))
print(*incl)
print(*nincl)
``` | instruction | 0 | 87,254 | 14 | 174,508 |
No | output | 1 | 87,254 | 14 | 174,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
Input
The first line contains integer n (2 β€ n β€ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.
Output
In the first line, print a single integer β the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
Examples
Input
4
xxXx
Output
1
XxXx
Input
2
XX
Output
1
xX
Input
6
xXXxXx
Output
0
xXXxXx | instruction | 0 | 87,917 | 14 | 175,834 |
Tags: implementation
Correct Solution:
```
n=input()
n=int(n)
y=input()
x_s=0
x_c=0
b=""
for i in range(n):
if y[i]=='x':
x_s+=1
else:
x_c+=1
if x_s==x_c:
print(0)
for i in y:
print(i ,end="")
if x_s>x_c:
u=n/2-x_c
o=n/2-x_c
while u>0:
for i in range(n):
if y[i]=='x' and not u<1:
b+='X'
u -= 1
else:
b+=y[i]
print(int(o))
for i in b:
print(i, end="")
if x_s<x_c:
u=n/2-x_s
o = n / 2 - x_s
while u>0:
for i in range(n):
if y[i]=='X' and not u<1:
b+='x'
u-=1
else:
b+=y[i]
print(int(o))
for i in b:
print(i, end="")
``` | output | 1 | 87,917 | 14 | 175,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
Input
The first line contains integer n (2 β€ n β€ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.
Output
In the first line, print a single integer β the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
Examples
Input
4
xxXx
Output
1
XxXx
Input
2
XX
Output
1
xX
Input
6
xXXxXx
Output
0
xXXxXx | instruction | 0 | 87,918 | 14 | 175,836 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = list(input())
count = s.count('X')
if count < n//2:
t = count
for i in range(n):
if t < n//2 and s[i] == 'x':
s[i] = 'X'
t += 1
print(t-count)
print(''.join(s))
elif count > n//2:
t = count
for i in range(n):
if t > n//2 and s[i] == 'X':
s[i] = 'x'
t -= 1
print(count-t)
print(''.join(s))
else:
print(0)
print(''.join(s))
``` | output | 1 | 87,918 | 14 | 175,837 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.