답안 #127004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127004 2019-07-08T19:00:07 Z Lawliet Sure Bet (CEOI17_sure) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
 
#define MAX 1010
 
using namespace std;
 
int n;
 
double ans = -4000000.0;
 
double a[MAX];
double b[MAX];
double ansA[MAX];
double ansB[MAX];
double mxAnsB[MAX];

bool test(double k)
{
	for(int qtdA = 0 ; qtdA <= n ; qtdA++)
	{
		double aux = ansA[qtdA] - k;

		if(ansA[qtdA] < k) continue;

		int mxQtdB = floor( aux );

		//printf("----------------- qtdA = %d        mxQtdB = %d\n",qtdA,mxQtdB);

		if(mxAnsB[ mxQtdB ] >= qtdA) return true;
	}

	return false;
}

double bs()
{
	double l = 0, r = 300000000.0;

	for(int cnt = 0 ; cnt <= 500 ; cnt++)
	{
		double m = (l + r)/2;

		//printf("l = %lf  r = %lf  m = %lf\n",l,r,m);

		if(test(m)) l = m;
		else r = m;
	}

	return l;
}

void init()
{
	sort(a + 1 , a + n + 1);
	sort(b + 1 , b + n + 1);

	for(int g = 1 ; g <= n ; g++)
	{
		ansA[g] = ansA[g - 1] + a[n - g + 1];
		ansB[g] = ansB[g - 1] + b[n - g + 1];

		//printf("g = %d        ansA = %lf\n",g,ansA[g]);
	}

	for(int g = 1 ; g <= n ; g++)
	{
		ansA[g] -= g;
		ansB[g] -= g;

		mxAnsB[g] = max(mxAnsB[g - 1] , ansB[g]);
	}


}
 
int main()
{
	scanf("%d",&n);
 
	for(int g = 1 ; g <= n ; g++)
		scanf("%lf %lf",&a[g],&b[g]);
 
	init();
 
	printf("%.4lf\n",bs());
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
sure.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lf %lf",&a[g],&b[g]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -