Daa Skill Week 3
Daa Skill Week 3
Sri lekha
Code:
def decentNumber(n):
# Start with the largest number of 5's possible, which must be divisible by 3
fives = n
while fives % 3 != 0:
fives -= 5
if fives < 0:
print("-1")
else:
threes = n - fives
# Read input
t = int(input().strip())
for _ in range(t):
n = int(input().strip())
decentNumber(n)
2. Priyanka and Toys
Code:
def toys(w):
w.sort()
containers = 0
# Step 3: Use a pointer to track the starting point of the current container
i=0
n = len(w)
while i < n:
min_weight = w[i]
containers += 1
i += 1
return containers
# Example usage:
if __name__ == '__main__':
n = int(input().strip())
w = list(map(int, input().rstrip().split()))
result = toys(w)
print(result)
3. Largest Permutation
Code:
n = len(arr)
for i in range(n):
if k <= 0:
break
# The value that should ideally be at this position for the largest permutation
ideal_value = n - i
continue
ideal_index = index_map[ideal_value]
index_map[arr[ideal_index]] = ideal_index
index_map[arr[i]] = i
k -= 1
return arr
# Example usage:
if __name__ == '__main__':
n, k = map(int, input().strip().split())
Code:
prices.sort()
# Step 2: Initialize the number of toys and the current total cost
num_toys = 0
total_cost = 0
# Step 3: Iterate through the sorted prices and count the number of toys
total_cost += price
num_toys += 1
else:
break
return num_toys
# Example usage:
if __name__ == '__main__':
n, k = map(int, input().strip().split())
result = maximumToys(prices, k)
print(result)
Code:
def jimOrders(orders):
# Calculate the serve times and pair them with customer numbers
# Sort the serve times, primarily by serve time and secondarily by customer number
# Extract and return the customer numbers in the order of sorted serve times
# Example usage:
if __name__ == '__main__':
import sys
input = sys.stdin.read
data = input().strip().split()
n = int(data[0])
orders = []
for i in range(n):
orders.append((int(data[2*i+1]), int(data[2*i+2])))
result = jimOrders(orders)