题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3850
题解:类似于国王游戏,推一下相邻两个元素交换的条件然后排个序就可以了。
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 200000+5 #define maxm 200000+5 #define eps 1e-10 #define ll long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) #define mod 1000000007 using namespace std; inline int read() { int x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
struct rec{int x,y;}a[maxn];
int n;
inline bool cmp(rec a,rec b){return a.x*b.y<b.x*a.y;} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); n=read();
for1(i,n)a[i].x=read();
for1(i,n)a[i].y=read();
sort(a+,a+n+,cmp);
ll ans=,sum=;
for1(i,n)
{
sum+=a[i].x;
ans+=sum*(ll)a[i].y;
}
cout<<ans<<endl; return ; }