-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ_1744.cpp
More file actions
58 lines (44 loc) · 1.09 KB
/
BOJ_1744.cpp
File metadata and controls
58 lines (44 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX 10001
using namespace std;
int main(void)
{
int N;
int sum=0;
int cnt =0;
priority_queue <int,vector<int>,greater<int>> positive;
priority_queue <int> negative;
cin >> N;
for(int i=0;i<N;i++){
int num;
cin >> num;
if(num == 1) sum+=1;
else if(num == 0) cnt++;
else if (num > 0 ) positive.push(num);
else negative.push(num);
}
if(positive.size()%2 != 0) positive.push(1);
if(negative.size()%2 != 0) {
if(cnt != 0) negative.push(0);
else negative.push(1);
}
while(!positive.empty()){
int num1 = positive.top();
positive.pop();
int num2 = positive.top();
positive.pop();
sum += num1*num2;
}
while(!negative.empty()){
int num1 = negative.top();
negative.pop();
int num2 = negative.top();
negative.pop();
sum += num1*num2;
}
cout << sum;
return 0;
}