fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef pair<ll, ll> PII;
  6. typedef vector<int> VI;
  7.  
  8. #define MAXN 200001
  9. #define pb push_back
  10. #define mp make_pair
  11. #define MOD (ll)1e9+7
  12. #define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  13. #define rep(i, a, b) for(int i = a; i < b; ++i)
  14.  
  15. int n, x;
  16. vector<pair<PII, PII> > a;
  17.  
  18. int main() {
  19. FASTIO
  20. cin >> n >> x;
  21. rep(i, 0, n) {
  22. int l, r, cost;
  23. cin >> l >> r >> cost;
  24. a.pb(mp(mp(r-l+1, cost), mp(l, r)));
  25. }
  26. sort(a.begin(), a.end());
  27. ll ans = 30000000000000;
  28. int cc = 0;
  29. int i = 0, j = n-1;
  30. for(i = 0; i < n; ) {
  31. int dur1 = a[i].first.first;
  32. int dur2 = a[j].first.first;
  33. ll cost = a[i].first.second + a[j].first.second;
  34. if(i == j)
  35. break;
  36. if(dur1+dur2 > x) {
  37. --j;
  38. }
  39. else if(dur1+dur2 == x) {
  40. if(a[i].second.first > a[j].second.second || a[j].second.first > a[i].second.second)
  41. ans = min(ans, cost);
  42. --j;
  43. }
  44. else
  45. ++i;
  46. }
  47. if(ans == 30000000000000)
  48. ans = -1;
  49. cout << ans;
  50. }
  51.  
Success #stdin #stdout 0s 16056KB
stdin
Standard input is empty
stdout
-1