https://www.acmicpc.net/problem/1744
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int sizeF =0, sizeS=0;
const int MAX = 10000;
int arr[MAX];
int arrm[MAX];
// 수 묶기
int solution(){
int answer = 0;
// 양수
sort(arr, arr+sizeF);
for(int i=0;i<sizeF-1;i+=2){
int idx = sizeF -1 - i;
if(arr[idx-1] * arr[idx] <= arr[idx]){
answer += arr[idx] + arr[idx-1];
}else{
answer += arr[idx] * arr[idx-1];
}
}
if(sizeF % 2 == 1) answer += arr[0];
// 음수
sort(arrm, arrm+sizeS);
for(int i=0;i<sizeS-1;i+=2){
int idx = sizeS -1 - i;
answer += arrm[idx] * arrm[idx-1];
}
if(sizeS % 2 == 1) answer -= arrm[0];
return answer;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>> n;
int a;
for(int i=0;i<n;i++){
cin>>a;
if(a <= 0) arrm[sizeS++] = -a;
else arr[sizeF++] = a;
}
cout<< solution()<<endl;
return 0;
}
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10000],n,r;
int main() {
scanf("%d", &n);
int i, j;
for (i = 0; i < n; i++) scanf("%d", a + i);
sort(a, a + n);
for (i = 0; i < n - 1 && a[i + 1] < 1; i += 2) r += a[i] * a[i + 1];
for (j = n - 1; j&&a[j - 1] > 1; j -= 2) r += a[j] * a[j - 1];
for (; i <= j; i++) r += a[i];
printf("%d", r);
return 0;
}