# 단순 구현
양수 음수 0에 대한 경우의 수를 나눠서 해결한다.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #define MAX 1005 #define INF 987654321 #define MOD 1000000 #pragma warning(disable:4996) using namespace std; typedef long long ll; typedef pair<int, int> pi; int n,a; vector<int> v; priority_queue<int> ans; int main() { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a); v.push_back(a); } sort(v.begin(),v.end()); ans.push(v[n-1]*v[n-2]*v[n-3]); // 모두 양수인경우, 음수인 경우 ans.push(v[n-1]*v[n-2]); // 양수 2개 음수 한개 ans.push(v[0]*v[1]*v[n-1]); // 음수 2개 이상 양수 한개 이상 ans.push(v[0]*v[1]); // 음수 2개와 0 printf("%d",ans.top()); return 0; }
'IT > BOJ' 카테고리의 다른 글
백준(BOJ) 11068 회문인 숫자 * (0) | 2018.08.16 |
---|---|
백준(BOJ) 13328 Message Passing * (0) | 2018.08.11 |
백준(BOJ) 13325 이진트리 * (0) | 2018.08.10 |
백준(BOJ) 14754 pizza boxes * (0) | 2018.08.08 |
백준(BOJ) 14746 Closest Pair * (0) | 2018.08.08 |