ddlz @ 2022-10-27 14:37:33
s0 = input().split()
n = int(s0[0])#苹果数n
s = int(s0[1])#力气s
s1 = input().split()
a = int(s1[0])#椅子的高度a
b = int(s1[1])#陶陶手伸直的最大长度b
x = []
y = []
#每行两个数 苹果高度 xi,摘这个苹果需要的力气 yi
for num in range(1,n + 1) :
s2 = input().split()
xi = int(s2[0])
yi = int(s2[1])
x.append(xi)
y.append(yi)
yy = []
for num in range(0,n) :
if x[num] <= a + b :
yy.append(y[num])
total = 0
sl = s
yy.sort()
for yn in yy :
if sl - yn >= 0 :
sl = sl - yn
total = total + 1
print(total)
看这一块
yy = []
for num in range(0,n) :
if x[num] <= a + b :
yy.append(y[num])
这里很奇怪的,自己枚举就没问题,之前用index去错就噶了:
yy = y
for x0 in x :
if x0 >= a + b :
pos0 = x.index(x0)
del x[pos0]
del yy[pos0]
怎么回事啊,实在搞不懂啊
by 初雪_matt @ 2022-10-27 14:41:05
@ddlz 有没有一种可能,index这个函数在未找到时会爆异常错误
by ddlz @ 2022-10-27 15:22:20
@初雪_matt 但显示的是 ac ac wa ac wa