-
Notifications
You must be signed in to change notification settings - Fork 2
/
2285_josueyeon.cpp
62 lines (48 loc) · 1.09 KB
/
2285_josueyeon.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
59
60
61
// Tenary Search
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<pair<long long, long long>> town;
long long getDist(long long position)
{
long long result = 0;
for(int i = 0;i < town.size();i++)
{
if (town[i].first > position)
result += (town[i].first - position) * town[i].second;
else
result += (position - town[i].first) * town[i].second;
}
return result;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
// N(마을)
int N;
cin>>N;
town.clear();
for(int i = 0;i < N;i++)
{
long long a, b;
cin>>a>>b;
town.push_back({a, b});
}
long long low = -1e9;
long long high = 1e9;
while(low <= high)
{
long long mid = (low + high) / 2;
long long left = getDist(mid);
long long right = getDist(mid + 1);
if (left <= right)
high = mid - 1;
else
low = mid + 1;
}
cout<<low<<"\n";
return 0;
}