답안 #865529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865529 2023-10-24T09:29:01 Z vjudge1 Sure Bet (CEOI17_sure) C++17
0 / 100
1 ms 2652 KB
#include <bits/stdc++.h>
 
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fxd(x) fixed << setprecision(x)
#define all(a) (a.begin() , a.end())
#define popcount(x) __builtin_popcount(x)
#define lwb lower_bound
#define upb upper_bound
#define dl long double
#define ll long long
#define pb push_back
#define sz() size()
#define F first
#define S second
 
using namespace std;
 
const ll N = 2e5+9;

ll n;
dl a[N] , b[N] , zr=0;

dl calc(ll cnt){
	ll ind1=1 , ind2=1 , i=cnt;
	dl sum1=0 ,  sum2=0;
	while (cnt){
		cnt--;
		if (ind1>n){
			sum2+=b[ind2];
			ind2++;
			continue;
		}
		if (ind2>n){
			sum1+=a[ind1];
			ind1++;
			continue;
		}
		if (sum1<sum2)sum1+=a[ind1++];
		else if (sum1>sum2)sum2+=b[ind2++];
		else {
			if (a[ind1]>b[ind2])sum1+=a[ind1++];
			else sum2+=(b[ind2++]);
		}
	}
	sum1-=i;
	sum2-=i;
	return min(sum1 , sum2);
}

void solve(){
	cin >> n;
	for (int i = 1 ; i <= n ; i++)cin >> a[i] >> b[i];
	sort (a+1 , a+1+n);
	sort (b+1 , b+1+n);
	reverse (a+1 , a+1+n);
	reverse (b+1 , b+1+n);
	ll ind=n/2;
	dl ans=max(zr , calc(ind)) , lst1;
	ll l=ind;
	while (l>0){
		dl x;
		if (l==ind)x=calc(l);
		else x=lst1;
		ans=max(ans , x);
		dl y=calc(l-1);
		if (calc(l-1)<x)break;
		l--;
		lst1=y;
	}
	ll r=ind;
	dl lst;
	while (r<=2*n){
		dl x;
		if (r==ind)x=calc(r);
		else x=lst;
		ans=max(ans , x);
		dl y=calc(r+1);
		if (y<x)break;
		r++;
		lst=y;
	}
	cout << fxd(4) << ans;
}
	
signed main() {
	optimus_prime;
	solve();
return 0;
}

Compilation message

sure.cpp: In function 'void solve()':
sure.cpp:79:3: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |   if (y<x)break;
      |   ^~
sure.cpp:67:3: warning: 'lst1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |   if (calc(l-1)<x)break;
      |   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -