Python “最短”挑戰(12.23)
阿新 • • 發佈:2018-12-30
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)