- 题解
H
- 2024-9-10 20:41:16 @
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PAI;
int n,q,c;
PAI p[1010];
int u,maxn;
long long ans;
bool cmp (PAI x,PAI y)
{
return x.first>y.first;
}
int main ()
{
cin >> n;
for (int i=1; i<=n; i++)
cin >> p[i].first;
for (int i=1; i<=n; i++)
{
cin >> p[i].second;
if (p[i].second>1&&p[i].first>maxn)
{
u=i;
maxn=p[i].first;
}
}
if (u)
{
q+=p[u].first,c+=p[u].second-1;
p[u].first=0,p[u].second=0;
ans+=q;
sort (p+1,p+1+n,cmp);
for (int i=1; i<n; i++)
{
q+=p[i].first,c+=p[i].second-1;
ans+=q;
}
ans+=q*c;
}
else
{
for (int i=1; i<=n; i++)
ans+=p[i].first;
}
cout << ans << endl;
return 0;
}
0 comments
No comments so far...