-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_Lala_Land_and_Apple_Trees.cpp
58 lines (57 loc) · 1.19 KB
/
A_Lala_Land_and_Apple_Trees.cpp
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
58
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<pair<int, int>> pos, neg;
for (int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
if (x < 0)
{
neg.push_back(make_pair(x, y));
}
else
{
pos.push_back(make_pair(x, y));
}
}
int ans = 0;
sort(neg.begin(), neg.end(), greater<pair<int, int>>());
sort(pos.begin(), pos.end());
if (pos.size() < neg.size())
{
for (int i = 0; i < (int)pos.size(); i++)
{
ans += pos[i].second;
}
for (int i = 0; i < (int)pos.size() + 1; i++)
{
ans += neg[i].second;
}
}
else
{
for (int i = 0; i < (int)neg.size(); i++)
{
ans += neg[i].second;
}
if (pos.size() == neg.size())
{
for (int i = 0; i < (int)neg.size(); i++)
{
ans += pos[i].second;
}
}
else
{
for (int i = 0; i < (int)neg.size() + 1; i++)
{
ans += pos[i].second;
}
}
}
cout << ans;
}