Submission #317846

# Submission time Handle Problem Language Result Execution time Memory
317846 2020-10-30T14:14:41 Z nandonathaniel Sure Bet (CEOI17_sure) C++14
100 / 100
107 ms 3576 KB
#include<bits/stdc++.h>
using namespace std;

double a[100005],b[100005];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i] >> b[i];
		a[i]-=1.0;b[i]-=1.0;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	sort(b+1,b+n+1);
	reverse(b+1,b+n+1);
	for(int i=1;i<=n;i++){
		a[i]+=a[i-1];
		b[i]+=b[i-1];
	}
	double ans=0;
	for(int i=1;i<=n;i++){
		bool state=(a[i]-1.0)>=(b[1]-(double)i);
		int ki=1,ka=n,res;
		while(ki<=ka){
			int mid=(ki+ka)/2;
			bool sini=((a[i]-(double)mid)>=(b[mid]-(double)i));
			if(sini==state){
				res=mid;
				ki=mid+1;
			}
			else ka=mid-1;
		}
		if(state){
			ans=max(ans,b[res]-(double)i);
			if(res+1<=n)ans=max(ans,a[i]-(double)(res+1));
		}
		else{
			ans=max(ans,a[i]-1.0);
		}
	}
	cout << fixed << setprecision(4) << ans << '\n';
	return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:37:45: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |    if(res+1<=n)ans=max(ans,a[i]-(double)(res+1));
      |                                         ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 94 ms 1912 KB Output is correct
18 Correct 107 ms 3192 KB Output is correct
19 Correct 99 ms 3192 KB Output is correct
20 Correct 96 ms 3192 KB Output is correct
21 Correct 103 ms 3576 KB Output is correct
22 Correct 96 ms 3192 KB Output is correct
23 Correct 97 ms 3192 KB Output is correct
24 Correct 96 ms 3360 KB Output is correct
25 Correct 95 ms 3196 KB Output is correct
26 Correct 104 ms 3576 KB Output is correct