File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
CompetitiveProgramming/HackerEarth/Algorithms/Greedy Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments