Skip to content

Commit 87d1ead

Browse files
committed
Added HackerEarth Greedy problems
1 parent 71f7668 commit 87d1ead

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# You are given container full of water. Container can have limited amount of water. You also have
2+
# N bottles to fill. You need to find the maximum numbers of bottles you can fill.
3+
#
4+
# Input:
5+
# First line contains one integer, T, number of test cases.
6+
# First line of each test case contains two integer, N and X, number of bottles and capacity of the container.
7+
# Second line of each test case contains
8+
# N space separated integers, capacities of bottles.
9+
#
10+
# Output:
11+
# For each test case print the maximum number of bottles you can fill.
12+
#
13+
# Constraints:
14+
# 1≤T≤100
15+
# 1≤N≤104
16+
# 1≤X≤109
17+
#
18+
# SAMPLE INPUT
19+
# 1
20+
# 5 10
21+
# 8 5 4 3 2
22+
#
23+
# SAMPLE OUTPUT
24+
# 3
25+
26+
for _ in range(int(input())):
27+
N, capacity = map(int, input().split())
28+
capacities = [int(bottle) for bottle in input().split()]
29+
capacities.sort()
30+
check, bottles = 0, 0
31+
for i in range(len(capacities)):
32+
if check > capacity:
33+
bottles -= 1
34+
break
35+
bottles += 1
36+
check += capacities[i]
37+
38+
print(bottles)

0 commit comments

Comments
 (0)