#include <iostream>
#include <stack>
#include <cmath>
#include <string.h>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <map>
using namespace std;
//p //w //d
vector< pair<long long,pair<long long,long long>>> arr;
//p //w //d
long long calc(long long concert) {
long long total = 0;
for (int i=0; i<arr.size(); i++) {
long long totaldis = std::abs(concert-arr[i].first);
if (totaldis > arr[i].second.second) {
long long mintravel = totaldis - arr[i].second.second;
total += mintravel*arr[i].second.first;
}
}
return total;
}
int main(){
int n;
cin >> n;
long long x;
long long y;
long long z;
long long right = -10000000;
long long ans = 0;
long long left = 10000000;
for(int i = 0; i < n; i++){
cin >> x >> y >> z;
arr.push_back(make_pair(x, make_pair(y,z)));
if(right < x)
right = x;
if(left > x)
left = x;
}
while (left<=right)
{
long long mid = (left+right)/2;
long long midtime = calc(mid);
long long midright = calc(mid+1);
long long midleft = calc(mid-1);
if (midtime <= midright && midtime <= midleft)
{
ans = midtime;
break;
}
else if (midtime <= midright)
{
right = mid-1;
}
else
{
left = mid+1;
}
}
cout << ans;
return 0;
}
top of page
Recent Posts
See All#include  <iostream> #include  <vector> int  main (){ long  long  N; std :: cin >>  N; std :: vector < long  long >  mins (N +  ...
0
#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c,...
0
s1 = input() s2 = input() silly = '' silly_o = '' quiete = '-' i = 0 j = 0 while i < len(s1) and j < len(s2): if s1[i] != s2[j]: if...
0
bottom of page
Comments