#include using namespace std; int Index(const vector& sorted_vector, int n) { int low = 0; int high = sorted_vector.size() - 1; int closest_index = -1; while (low <= high) { int mid = (low + high) / 2; if (sorted_vector[mid] == n) { return mid; } else if (sorted_vector[mid] < n) { low = mid + 1; } else { high = mid - 1; } if (closest_index == -1 || abs(sorted_vector[mid] - n) < abs(sorted_vector[closest_index] - n)) { closest_index = mid; } } return closest_index; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int pohon, ikan; cin>>pohon>>ikan; vector phn; long long ans=0; for (int i=0; i>temp; phn.push_back(temp); } for (int i=0; i>posisi>>pow1>>pow2; int selisih=pow2-pow1; int jarmin=abs(phn[Index(phn, posisi)]-posisi); if(jarmin<=selisih){ ans+=(pow2-jarmin); } else ans+=pow1; } cout<