利用重心 import sys import math n = int(sys.stdin.readline().strip()) x=sys.stdin.readline().split(' ') y=sys.stdin.readline().split(' ') for i in range(0,n): x[i]=int(x[i]) y[i]=int(y[i]) point=[] nd=dict() for i in range(0,n): nd[str(x[i])+','+str(y[i])]=nd.get(str(x[i])+','+str(y[i]),0)+1 b=dict(sorted(nd.items(), key=lambda d:d[1], reverse = True)) sum=0 j=0 res=[] tup=[] print (b) for i in range(1,n+1): while(sum<i): sum+=list(b.values())[j] x,y=list(b.keys())[j].split(',') tup.append([int(x),int(y),list(b.values())[j]]) j+=1 ss1=[0,0] ss2=0 # print (tup) for item in tup: ss1=[item[0]*item[2]+ss1[0],item[1]*item[2]+ss1[1]] ss2+=item[2] # print(ss1,ss2) xx=round(ss1[0]/ss2) yy=round(ss1[1]/ss2) # print(xx,yy) re=0 sssss=0 for item in tup: mm=min(item[2],i-sssss) re+=(abs(xx-item[0])+abs(yy-item[1]))*mm sssss+=mm res.append(re) print (res)