답안 #136814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136814 2019-07-26T10:12:22 Z RiscadoA Pareto (COCI17_pareto) C++14
80 / 80
234 ms 3348 KB
#include <bits/stdc++.h>

const int MAX_N = 300000;

int N;
double A, B, C[MAX_N];

void solve()
{
	// Sort bank accounts
	std::sort(std::begin(C), std::begin(C) + N, std::greater<double>());
	
	// Get the total amount of money in the bank
	double sum_C = 0.0;
	for (int i = 0; i < N; ++i)
		sum_C += C[i];

	double cur_C = 0.0;
	A = 0.0;
	B = 0.0;
	for (int i = 0; i < N; ++i) {
		cur_C += C[i];
		
		double new_A = ((double)(i + 1) / (double)N) * 100.0;
		double new_B = (cur_C / sum_C) * 100.0;
		
		if (new_B - new_A < B - A)
			break;
		A = new_A;
		B = new_B;
	}
}

int main()
{
	std::cin >> N;
	for (int i = 0; i < N; ++i)
		std::cin >> C[i];

	solve();

	std::cout << A << "\n" << B;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 73 ms 1656 KB Output is correct
7 Correct 161 ms 2552 KB Output is correct
8 Correct 234 ms 3348 KB Output is correct