답안 #897703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897703 2024-01-03T15:08:45 Z LCJLY Sure Bet (CEOI17_sure) C++14
100 / 100
78 ms 6744 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;

void solve(){	
	int n;
	cin >> n;
	ld arr[n];
	ld arr2[n];
	
	for(int x=0;x<n;x++){
		cin >> arr[x] >> arr2[x];
		if(arr[x]<1.0) arr[x]=1.0;
		if(arr2[x]<1.0) arr2[x]=1.0;
	}
	
	sort(arr,arr+n,greater<ld>());
	sort(arr2,arr2+n,greater<ld>());
	
	ld prefix[n];
	
	ld counter=0.0;
	for(int x=0;x<n;x++){
		counter+=arr2[x];
		prefix[x]=counter;
	}
	
	ld best=0.0;
	counter=0.0;
	int cur=0;
	for(int x=0;x<n;x++){
		//int cur=0;
		counter+=arr[x];
		
		//show(counter,counter);
		
		while(cur<n-1&&prefix[cur+1]<counter){
			cur++;
		}
	
		
		//show(cur,cur);
		best=max(best,min(counter-(ld)(cur+x+2),prefix[cur]-(ld)(cur+x+2)));
		if(cur<n-1){
			best=max(best,min(counter-(ld)(cur+x+3),prefix[cur+1]-(ld)(cur+x+3)));
		}
		//show(best,best);
	}
	
	cout << fixed << setprecision(4) << best;
}
 
int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	//freopen("redistricting.in", "r", stdin);
	//freopen("redistricting.out", "w", stdout);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 372 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 372 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 69 ms 5108 KB Output is correct
18 Correct 67 ms 6484 KB Output is correct
19 Correct 70 ms 6380 KB Output is correct
20 Correct 67 ms 6480 KB Output is correct
21 Correct 71 ms 6744 KB Output is correct
22 Correct 71 ms 6484 KB Output is correct
23 Correct 69 ms 6392 KB Output is correct
24 Correct 68 ms 6384 KB Output is correct
25 Correct 70 ms 6484 KB Output is correct
26 Correct 78 ms 6736 KB Output is correct