题解:T594862 T2 上坟
Taikoier_Ura · · 题解
思路
贪心,先去
好吧如果你过不了就只能是人傻常数大了。
Code:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1000000 + 5;
int a[N], t[N], tmp[N];
int n;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
for (int i = 1; i <= n; i++) {
tmp[i] = a[i] * t[i];
}
sort(tmp + 1, tmp + n + 1);
int ans = 0ll;
for (int i = 1; i <= n; i++) {
ans += (long long)i * tmp[i];
}
cout << ans;
return 0;
}