Python “最短”挑战(12.23)

Description

现有n项工作,你希望雇佣一些员工完成它们。你有m个员工可以雇佣,一个能力值为x的员工可以完成一个难度不超过x的工作,且需要支付x元工资。如何雇佣员工才能完成所有工作,并且支付的工资为多少?需要注意一个员工只能完成一项工作,且不能被雇佣两次。

Input

三行。第一行为正整数n和m,第2行为n项工作的难度,第3行为m个员工的能力值,所有数据用空格分隔。

Output

最少工资。如果无解输出None。
其余要求同首题

Sample Input

2 3
5 4
7 8 4

Sample Output

11

Reference code

[n,m]=list(map(int,input().split(' ')))
if n>m:
    print(None)
else:
    x=sorted(list(map(int,input().split(' '))))
    y=sorted(list(map(int,input().split(' '))))
    ans,buf=0,0
    for i in range(n):
        if x[n-1]>y[m-1]:
            print(None)
            break
        for j in range(buf,m):
            if x[i]<=y[j]:
                ans+=y[j]
                y[j]=0
                buf=j+1
                break
    print(ans)

猜你喜欢

转载自blog.csdn.net/qq_43549984/article/details/85225243