Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define eb emplace_back
- #define mk make_pair
- #define fi first
- #define se second
- #define cc(x) cout << #x << " = " << x << endl
- #define ok cout << "ok" << endl
- #define endl '\n'
- typedef long long ll;
- typedef pair<ll,ll> ii;
- const int INF = 0x3f3f3f3f;
- const double PI = acos(-1.0);
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >>n;
- vector<ii> v;
- ll amin = -1;
- vector<ll> dans;
- for(int i = 0; i < n; i++) {
- ll a, t; cin >>a >>t;
- v.pb(ii(a, t));
- if(i < n-1) dans.pb(a*t);
- }
- sort(v.begin(), v.end(), [](const ii &a, const ii &b) {
- return a.fi*a.se >= b.fi*b.se;
- });
- ll ans = 0;
- for(int i = 0; i < n; i++) {
- ans += ((n-i-1)*(dans[i]-(v[i].fi*v[i].se)));
- cc(ans);
- }
- cout <<ans <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement