๐ŸŒžAlgorithm/๐Ÿ”ฅBaekjoon

[Baekjoon] 11597_Excellence

๋ฟŒ์•ผ._. 2025. 3. 24. 14:31
๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/11597)

< Excellence >

 

๋ฌธ์ œ ํ’€์ด 

 

ํŒ€์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ํ‰์ ์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ž…๋ ฅ๋ฐ›์€ ํ‰์ ์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ์ž‘์€ ๊ฐ’๊ณผ ํฐ ๊ฐ’์„ ๋”ํ•œ๋‹ค.

๋งŒ์•ฝ ์ž…๋ ฅ๊ฐ’์ด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค๋ฉด

4
1
2
3
5

๋จผ์ € ํ‰์ ์„ ์ •๋ ฌํ•œ๋‹ค.

1 2 3 5

1+5 = 6

2+3 = 5

์ด๋ฏ€๋กœ X์˜ ์ตœ๋Œ“๊ฐ’์€ 5๊ฐ€ ๋œ๋‹ค.

 

my solution (Java)

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Arrays;
 
 public class _11597_ { // Excellence
 
 	public static void main(String[] args) throws IOException {
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 
 		int n = Integer.parseInt(bf.readLine());
 
 		int arr[] = new int[n];
 		for (int i = 0; i < n; i++) {
 			arr[i] = Integer.parseInt(bf.readLine());
 		}
 
 		Arrays.sort(arr);
 
 		int result = Integer.MAX_VALUE;
 		for (int i = 0; i < n / 2; i++) {
 			result = Math.min(result, arr[i] + arr[n - 1 - i]);
 		}
 
 		System.out.println(result);
 	}
 }
๋ณ€์ˆ˜)
n : ํ•™์ƒ ์ˆ˜
arr : ํ‰์  ์ €์žฅ
result : ํŒ€์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ํ‰์ ์˜ ์ตœ๋Œ“๊ฐ’

 

ํ•™์ƒ ์ˆ˜ n์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. n๋งŒํผ ํ‰์ ์„ ์ž…๋ ฅ๋ฐ›์•„ arr์— ์ €์žฅ ํ›„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค. arr์„ ์ˆœ์ฐจ ํƒ์ƒ‰ํ•˜๋ฉฐ ์•ž๊ณผ ๋’ค๋ฅผ ๋”ํ•ด result์˜ ์ตœ์†Ÿ๊ฐ’์„ ์ฐพ๋Š”๋‹ค.

 

์ตœ์ข… ํŒ€์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ํ‰์ ์˜ ์ตœ๋Œ“๊ฐ’์ธ result๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.  



 

'๐ŸŒžAlgorithm > ๐Ÿ”ฅBaekjoon' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Baekjoon] 23895_Allocation  (0) 2025.03.26
[Baekjoon] 6566_์• ๋„ˆ๊ทธ๋žจ ๊ทธ๋ฃน  (0) 2025.03.25
[Baekjoon] 6123_O Those Fads  (0) 2025.03.21
[Baekjoon] 12596_Odd Man Out (Large)  (0) 2025.03.20
[Baekjoon] 26975_Cow College  (0) 2025.03.18