문제 : https://www.acmicpc.net/problem/1448

#include<iostream>
#include<algorithm>
using namespace std;
// 가장 긴 변의 길이가 댜른 두변의 합보다 작아야 한다.
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
int arr1[1000000];
for(int i = 0; i < n; i++) {
cin >> arr1[i];
}
sort(arr1, arr1+n, greater<int>());
int total = 0;
for(int j = 0; j <= n / 2; j++) {
if(arr1[j] < arr1[j+1] + arr1[j+2]) {
total = arr1[j] + arr1[j+1] + arr1[j+2];
cout << total;
break;
}
}
if(total == 0) {
cout << -1;
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Collections;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
Integer [] arr = new Integer[n];
for(int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(arr, Collections.reverseOrder());
int total = -1;
for(int j = 0; j < n-2; j++) {
if(arr[j] < arr[j+1] + arr[j+2]) {
total = arr[j] + arr[j+1] + arr[j+2];
break;
}
}
bw.write(total + "\n");
bw.flush();
bw.close();
br.close();
}
}