-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccc_2021_s3.cpp
51 lines (48 loc) · 1.06 KB
/
ccc_2021_s3.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
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<int> vi;
vector<vector<ll>> f;
ll getScore(ll p) {
ll ans = 0;
for(auto i: f) {
ll walk = abs(p-i[0])-i[2];
if(walk > 0) {
ans += walk * i[1];
}
}
return ans;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
ll N,low = INT_MAX, high = 0;
cin >> N;
for(ll i = 0; i < N; i++) {
vector<ll> inp(3);
cin >> inp[0] >> inp[1] >> inp[2];
f.push_back(inp);
low = min(inp[0],low);
high = max(inp[0],high);
}
ll mid = 0, S = 0;
while(low <= high) {
mid = (low+high)/2;
S = getScore(mid);
ll left = getScore(mid-1);
ll right = getScore(mid+1);
if(S < right && S < left) {
break;
}
if(S == right || S == left) {
break;
}
if(S < right) {
high = mid - 1;
}
else if(S < left) {
low = mid+1;
}
}
cout << S;
}