#include #include #include #include #include #include #include using namespace std; template inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } using ll = long long; ll K[303030], L[303030], D[303030]; ll two[100]; int n; bool F(ll x) { ll cnt = 0; for (int i=0; i> n; for (int i=0; i> K[i] >> L[i] >> D[i]; } ll l=-1, r=1e18; while (r-l>1) { ll m = (r+l)/2; if (F(m)) r = m; else l = m; } cout << r << endl; }