Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- int n; cin >> n;
- vector<pair<pair<int,int>, int>> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i].first.first;
- a[i].second = i + 1;
- }
- for (int i = 0; i < n; i++) {
- cin >> a[i].first.second;
- }
- sort(a.begin(), a.end(), [](pair<pair<int,int>, int> &a, pair<pair<int,int>, int> &b) -> bool {
- pair<int,int> x = a.first, y = b.first;
- return x.first * y.second > y.first * x.second;
- });
- long long ans = 0, sumTime = 0;
- for (int i = 0; i < n; i++) {
- sumTime += a[i].first.second;
- ans += a[i].first.first * sumTime;
- }
- cout << ans << '\n';
- for (int i = 0; i < n; i++) {
- cout << a[i].second << ' ';
- }
- cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement