
1. 문제 풀이 아이디어
- 최대값을 찾고, 나머지 합의 절반과 더해 문제를 해결할 수 있다.
2. 나의 정답 코드
using (StreamReader sr = new StreamReader(Console.OpenStandardInput()))
using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()))
{
int n = int.Parse(sr.ReadLine());
double sum = 0;
int max = 0;
string[] split = sr.ReadLine().Split();
for (int i = 0; i < n; i++)
{
int x = int.Parse(split[i]);
sum += x;
max = Math.Max(max, x);
}
sw.WriteLine((sum - max) / 2 + max);
}
3. 정리
sum
을 사용해 모든 값을 더하면서 최대값max
를 찾는다.
(sum - max) / 2 + max
를 계산하여 결과를 출력한다.
Share article