fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 34643 (C++) Star Guardians
최초 업로드: 2025-11-06 13:27:24
최근 수정 시간: 2025-11-06 13:27:24
게시자: rlatjwls3333
카테고리: 백준
조회수: 8
# [Silver V] Star Guardians [문제 링크](https://www.acmicpc.net/problem/34643) ## 문제 설명 <p>Jenny and Ojas are part of an elite group of competitive programmers called the Star Guardians. Their next job - to do well in the NAQ!</p> <p>The Star Guardians are working to assemble a team for the NAQ. They are yet to decide their team, but for each person in the group, it is known how many problems that person will solve.</p> <p>The Star Guardians are also well-versed in teamwork, so they will solve an additional number of problems based solely on the size of their team.</p> <p>The Star Guardians want to field a team that maximizes the average number of problems solved per team member. Compute the maximum average they can attain. You may assume the NAQ has infinitely many problems, so the Star Guardians will not run out of problems to solve.</p> ## 입력 <p>The first line of input contains a single integer, $n$ ($1 \le n \le 10)$, the number of Star Guardians.</p> <p>The next line contains $n$ integers $a$ ($0 \le a \le 10^9$), with the $i$<sup>th</sup> integer being the additional number of problems solved if the Star Guardians field a team of size $i$. It is guaranteed that these integers are monotonically increasing.</p> <p>The next line contains $n$ integers $s$ ($0 \le s \le 10^8$), which is the number of problems each Star Guardian can solve.</p> ## 출력 <p>Output a single number, which is the maximum average number of problems per team member attainable. Your output will be considered correct if it has absolute or relative error at most $10^{-6}$ from the correct answer.</p> ## 풀이 크기 i인 팀에 대해 개별 솔브수가 큰 i명을 선택하는 것이 그리디합니다. 솔브수 기준으로 내림차순으로 정렬하여 팀의 1 ~ N 크기에 대해 평균 솔브수의 최댓값을 계산하면 됩니다. ``` c++ #include<bits/stdc++.h> using namespace std; double a[10], s[10]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i=0;i<n;i++) cin >> a[i]; for(int i=0;i<n;i++) cin >> s[i]; sort(s, s+n, greater<double>()); for(int i=1;i<n;i++) s[i] += s[i-1]; double avg=0; for(int i=0;i<n;i++) avg = max(avg, (a[i]+s[i])/(i+1)); cout << setprecision(6) << fixed << avg; } ```