Advertisement
tuki2501

CAR.cpp

Sep 19th, 2022
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     cin.tie(0)->sync_with_stdio(0);
  6.     int n; cin >> n;
  7.     vector<pair<pair<int,int>, int>> a(n);
  8.     for (int i = 0; i < n; i++) {
  9.         cin >> a[i].first.first;
  10.         a[i].second = i + 1;
  11.     }
  12.     for (int i = 0; i < n; i++) {
  13.         cin >> a[i].first.second;
  14.     }
  15.     sort(a.begin(), a.end(), [](pair<pair<int,int>, int> &a, pair<pair<int,int>, int> &b) -> bool {
  16.         pair<int,int> x = a.first, y = b.first;
  17.         return x.first * y.second > y.first * x.second;
  18.     });
  19.     long long ans = 0, sumTime = 0;
  20.     for (int i = 0; i < n; i++) {
  21.         sumTime += a[i].first.second;
  22.         ans += a[i].first.first * sumTime;
  23.     }
  24.     cout << ans << '\n';
  25.     for (int i = 0; i < n; i++) {
  26.         cout << a[i].second << ' ';
  27.     }
  28.     cout << '\n';
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement