top of page

CCC 2021 S3 Lunch Concert

#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;
}

Recent Posts

See All

CCC '23 S2 - Symmetric Mountains

#include  <iostream> #include  <vector> int   main (){ long   long  N; std :: cin  >>  N; std :: vector < long   long >  mins (N  +  ...

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c,...

CCC '24 J4 - Troublesome Keys

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...

Comments


bottom of page