SHARE
TWEET

Untitled

a guest Jul 16th, 2019 66 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 pb push_back
  5. #define eb emplace_back
  6. #define mk make_pair
  7. #define fi first
  8. #define se second
  9. #define cc(x)   cout << #x << " = " << x << endl
  10. #define ok      cout << "ok" << endl
  11. #define endl '\n'
  12.  
  13. typedef long long ll;
  14. typedef pair<ll,ll> ii;
  15. const int INF = 0x3f3f3f3f;
  16. const double PI = acos(-1.0);
  17.  
  18. int main() {
  19.     ios_base::sync_with_stdio(false);
  20.  
  21.     int n;
  22.     cin >>n;
  23.  
  24.     vector<ii> v;
  25.     ll amin = -1;
  26.  
  27.     vector<ll> dans;
  28.     for(int i = 0; i < n; i++) {
  29.         ll a, t; cin >>a >>t;
  30.         v.pb(ii(a, t));
  31.         if(i < n-1) dans.pb(a*t);
  32.     }
  33.    
  34.     sort(v.begin(), v.end(), [](const ii &a, const ii &b) {
  35.         return a.fi*a.se >= b.fi*b.se;
  36.     });
  37.    
  38.     ll ans = 0;
  39.     for(int i = 0; i < n; i++) {
  40.         ans += ((n-i-1)*(dans[i]-(v[i].fi*v[i].se)));
  41.         cc(ans);
  42.     }
  43.  
  44.     cout <<ans <<endl;
  45.     return 0;
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top