This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e9;
const ll N = 1e5+55;
const int base = 313;
ll n, m, t, k, T, ans, q, tong, h[N], d[N], lab[N], fe[N];
ll a[N], b[N], c[N];
vector<ll> adj[N], kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void add(ll id, ll x)
{
for(; id; id -= id & -id)fe[id] = max(fe[id], x);
}
ll get(ll id)
{
ll total = 0;
for(; id <= n; id += id & -id)total = max(total, fe[id]);
return total;
}
bool cmp(ll& x, ll& y)
{
return x > y;
}
bool check(ll x)
{
ll total = 0;
for(int i = 1; i <= n; i ++)
{
total += b[i] - mod;
ll j = min(n, (total - x) / mod);
if(j < 0)continue;
if(d[j] - 1ll * i * mod >= x)return true;
}
return false;
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
ld x;
cin >> x;
a[i] = mod * x;
cin >> x;
b[i] = mod * x;
}
sort(a+1, a+1+n, cmp);
sort(b+1, b+1+n, cmp);
for(int i = 1; i <= n; i ++)d[i] = max(d[i-1], d[i-1] + a[i] - mod);
ll lf = 0, rt = mod * mod, mid;
while(lf <= rt)
{
mid = (lf + rt) / 2;
if(check(mid))lf = mid+1;
else rt = mid - 1;
}
cout << fixed << setprecision(4) << (long double) 1.0 * rt / mod;
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:81:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:82:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |