1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <cstdio> #include <iostream> #include <algorithm> #include <vector>
using namespace std;
struct P { int t, d; };
bool cmp(const P &a, const P &b) { return b.d * a.t < a.d * b.t; }
vector<P> v;
int N;
int main() { scanf("%d", &N); int i, total; total = 0; for(i=0;i<N;++i) { struct P p; scanf("%d %d", &p.t, &p.d); v.push_back(p); total += p.d; }
sort(v.begin(), v.end(), cmp); unsigned long long res = 0; for(i=0;i<N;++i) { total -= v[i].d; res += total * v[i].t * 2; }
cout << res << endl; return 0; }
|