#include #include #include #include #include #include #include #include #include using namespace std; struct arraycomp { bool operator()(const array& a, const array& b) const { return a[0] * b[1] < a[1] * b[0]; } }; int main() { int n; cin >> n; vector> v(n); int64_t contrib = 0; for(auto& x: v) { cin >> x[0] >> x[1]; contrib += x[0] * x[1]; } if(contrib == 0) return void(cout << "0\n"), 0; if(contrib > 0) { for(auto& x: v) x[0] *= -1; contrib *= -1; } assert(contrib < 0); double ret = 0; priority_queue, vector>, arraycomp> q; map> dp; for(int i = 0; i < n; i++) { auto [loc, weight] = v[i]; dp[loc] = {weight, 1}; q.push(array({weight, 1, loc})); } while(true) { assert(q.size()); auto [totweight, totnum, loc] = q.top(); q.pop(); if(dp[loc] != array({totweight, totnum})) continue; if(dp.upper_bound(loc) == dp.end()) { ret += (-contrib) / double(dp[loc][0]) * dp[loc][1]; break; } dp.erase(loc); auto it = dp.upper_bound(loc); assert(it != dp.end()); int64_t maxshift = (it->first - loc) * totweight; if(maxshift + contrib >= 0) { ret += (-contrib) / double(totweight) * totnum; break; } contrib += maxshift; auto nxtloc = it->first; ret += (nxtloc - loc) * totnum; auto [nweight, nnum] = dp[nxtloc]; dp[nxtloc] = {nweight + totweight, nnum + totnum}; q.push({(nweight + totweight), (nnum + totnum), nxtloc}); } cout << fixed << setprecision(39) << ret << "\n"; }