Вот код на питоне:
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)
Объяснение:
При необходимости могу пояснить построчно.
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("Пара не существует")
Uses Crt;
Var
a: array [1..10] of integer;
i,c,b: byte ;
Begin
ClrScr;
For i :=1 to 10 do
begin
a[i]:= random (10);
writeln(a[i]);
end;
writeln;
b:=a[1];
c:=a[10];
a[1]:=c;
a[10]:=b;
For i :=1 to 10 do
writeln(a[i]);
end.