Python 3.9
Объяснение:
c, d = map(int, input("Input c d: ").split())
a=int(c/c)
b=int(d/c)
dem=int(d/c)
if c*d<2000000000:
if d%c==0:
print(a*c, b*c)
for i in range(dem):
for j in range(dem,0,-1):
if a<=b:
if a*b==dem:
if b%a!=0:
b=b-1
else:
break
a=a+1
print("Пара не существует")
Вот код на питоне:
N = int(input())
objects = []
for i in range(N):
objects.append(list(map(int, input().split(
rezult = []
summ = 0
price = 0
while summ <= 40:
Max = 0
index = -1
for i in objects:
if i[1] > Max and i[0] + summ <= 40 and not objects.index(i) in rezult:
Max = i[1]
index = objects.index(i)
if index == -1:
rezult.append(index)
summ += objects[index][0]
price += objects[index][1]
for i in rezult:
print(i + 1)
print(summ, price)
При необходимости могу пояснить построчно.
Python 3.9
Объяснение:
c, d = map(int, input("Input c d: ").split())
a=int(c/c)
b=int(d/c)
dem=int(d/c)
if c*d<2000000000:
if d%c==0:
print(a*c, b*c)
for i in range(dem):
b=int(d/c)
for j in range(dem,0,-1):
if a<=b:
if a*b==dem:
if b%a!=0:
print(a*c, b*c)
b=b-1
else:
break
a=a+1
else:
print("Пара не существует")
Вот код на питоне:
N = int(input())
objects = []
for i in range(N):
objects.append(list(map(int, input().split(
rezult = []
summ = 0
price = 0
while summ <= 40:
Max = 0
index = -1
for i in objects:
if i[1] > Max and i[0] + summ <= 40 and not objects.index(i) in rezult:
Max = i[1]
index = objects.index(i)
if index == -1:
break
rezult.append(index)
summ += objects[index][0]
price += objects[index][1]
for i in rezult:
print(i + 1)
print(summ, price)
Объяснение:
При необходимости могу пояснить построчно.