像鱼666


私信TA

用户名:dotcpp0705695

访问量:924

签 名:

等  级
排  名 1061
经  验 3128
参赛次数 0
文章发表 39
年  龄 0
在职情况 学生
学  校 江南大学
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

n,m=map(int,input().split())

s=input().split()#竖切代价(n-1个数)

h=input().split()#横切代价(m-1个数)



s=[int(l)for l in s]

h=[int(p)for p in h]


s.sort(reverse=True)

h.sort(reverse=True)

count=0#代价


i=0

j=0

x=y=1#两个方向砍出来的木板数量


while i<n-1 and j<m-1:

    if s[i]>=h[j]:#先切代价大的

        count+=s[i]*y#乘以对面方向的数量

        i+=1

        x+=1

         

    else:

        count+=h[j]*x

        j+=1

        y+=1

       

if i==n-1:

    for j in range(j,m-1):

        count+=h[j]*x

        y+=1

else:

    for i in range(i,n-1):

        count+=s[i]*y

        x+=1


print(count)



 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区