Submission #229435

# Submission time Handle Problem Language Result Execution time Memory
229435 2020-05-04T13:24:18 Z bharat2002 Sure Bet (CEOI17_sure) C++14
0 / 100
5 ms 384 KB
/*input
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
#include<bits/stdc++.h>
using namespace std;
const int N=1e5 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl 
//Trace prints the name of the variable and the value.
long double a[N], b[N];int n;
long double bit[N];
bool sf(long double f, long double s)
{
	return f>s;
}
void build()
{
	bit[0]=0;
	for(int i=1;i<=n;i++) bit[i]=0;
	for(int i=1;i<=n;i++)
	{
		if(b[i]-i<=bit[i]) continue;
		bit[i]=b[i]-i;
		int ind=i+1;
		while(ind<=n)
		{
			bit[ind]=max(bit[ind], bit[i]);
			ind+=(ind&(-ind));
		}
	}
}
long double query(int ind)
{
	long double ret=0;
	while(ind>0)
	{
		ret=max(ret, bit[ind]);ind-=(ind&(-ind));
	}
	return ret;
}
bool p(long double x)
{
//	cout<<x<<": ";
	for(int i=1;i<=n;i++)
	{
		long double ti=i+0.0;
		int temp=(a[i]-ti-x);
		if(temp<1) continue;
		long double qval=query(temp);
//		cout<<i<<" "<<temp<<endl;
		if(qval-i>=x) return 1;
	}
	return 0;
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	long double low=0.000, high=3e8;
	sort(a+1, a+n+1, sf);sort(b+1, b+n+1, sf);
	for(int i=2;i<=n;i++) {a[i]+=a[i-1];b[i]+=b[i-1];}
	build();
	while(high-low>1e-8)
	{
		long double mid=(low+high)/2;
		if(p(mid)) low=mid;
		else high=mid;
	}
	cout<<fixed<<setprecision(4)<<low;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -