调了多少遍都全WA,dalao求条
#include<bits/stdc++.h>
using namespace std;
const int N=2000+5;
int n,q,w[N],e[N],p,pp;
long long ans;
bool cmp(int a,int b){
return a>b;
}
int main(){
cin>>n>>q;
p=pp=1;
for(int i=1;i<n;i++){
scanf("%d",&w[i]);
}
for(int i=1;i<q;i++){
scanf("%d",&e[i]);
}
sort(w+1,w+n,cmp);
sort(e+1,e+q,cmp);
while(p<n&&pp<q){
if(w[p]>e[pp]){
ans+=(w[p++]*pp);
}
else{
ans+=(w[pp++]*p);
}
}
while(p<n){
ans+=(w[p++]*pp);
}
while(pp<q){
ans+=(w[pp++]*p);
}
cout<<ans;
return 0;
}