Advertisement
Helicator

energy.cpp

Jan 28th, 2022
652
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define vi vector<int>
  6. #define vii vector<vi>
  7. #define ii pair<int,int>
  8. #define fi first
  9. #define sc second
  10. #define pb push_back
  11. #define stoi stoll
  12. #define popcnt __builtin_popcount
  13. #define getbit(x, k) ((x >> k) & 1)
  14. #define all(x) (x).begin(),(x).end()
  15. #define rall(x) (x).rbegin(),(x).rend()
  16. #define FOR(i,j,k) for(int i=j; i<(int)k; ++i)
  17. #define look(a) cerr <<#a<<": "<<a<<endl;
  18. #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
  19.  
  20. void solve()
  21. {
  22.     int n,m;
  23.     cin >> n >> m;
  24.     vector<ii> a(n), b(m);
  25.     FOR(i,0,n){
  26.         cin >> a[i].fi;
  27.         a[i].sc = i;
  28.     }
  29.     FOR(i,0,m){
  30.         cin >> b[i].fi;
  31.         b[i].sc = i;   
  32.     }
  33.     sort(rall(a)); // Neu lam nguoc la sai
  34.     sort(all(b));
  35.  
  36.     vector<ii> ans;
  37.     int s = 0;
  38.     FOR(i,0,n){
  39.         s += a[i].fi*b[i].fi;
  40.         ans.push_back({a[i].sc,b[i].sc});
  41.     }
  42.     sort(all(ans));
  43.     cout << s << '\n';
  44.     for(auto&i:ans) cout << i.sc + 1 << ' ';
  45. }
  46.  
  47. signed main()
  48. {
  49.     cin.tie(0)->sync_with_stdio(0);
  50.     freopen("in", "r", stdin);
  51.     freopen("out", "w", stdout);
  52.     int T = 1;
  53.     // cin >> T;
  54.     while (T--) {
  55.         solve();
  56.         cout << '\n';
  57.     }
  58.     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  59. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement