GerONSo

Untitled

Nov 16th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. /*
  2.  
  3. ∧_∧
  4. ( ・ω・。)つ━☆・*。
  5. ⊂  ノ    ・゜
  6. しーJ   Accepted
  7.  
  8. */
  9.  
  10.  
  11.  
  12. // #pragma GCC optimize("O3")
  13. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  14.  
  15. #include <bits/stdc++.h>
  16. #include <ext/pb_ds/assoc_container.hpp>
  17. #include <ext/pb_ds/tree_policy.hpp>
  18.  
  19. #define ll long long
  20. #define all(x) begin(x), end(x)
  21. #define x first
  22. #define y second
  23. #define int long long
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27.  
  28. typedef long double ld;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(14);
  39. #ifdef _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 1e6 + 10;
  46. const int MAXM = 600;
  47. const int INF = 1e9;
  48. const int BASE = 47;
  49. const int MOD = 43200;
  50. const int MAXLOG = 21;
  51.  
  52. vector<vector<int>> dp;
  53.  
  54. int get(int i, int v, int tl, int tr, int l, int r) {
  55. if(tl > r || tr < l) {
  56. return INF;
  57. }
  58. if(tl >+ l && tr <= r) {
  59. return dp[i][v];
  60. }
  61. int tm = (tl + tr) >> 1;
  62. int left = get(i, v * 2 + 1, tl, tm, l, r);
  63. int right = get(i, v * 2 + 2, tm + 1, tr, l, r);
  64. return min(left, right);
  65. }
  66.  
  67. void update(int i, int v, int tl, int tr, int pos, int val) {
  68. if(tl > pos || tr < pos) {
  69. return;
  70. }
  71. if(tl == tr) {
  72. dp[i][v] = min(dp[i][v], val);
  73. return;
  74. }
  75. int tm = (tl + tr) >> 1;
  76. update(i, v * 2 + 1, tl, tm, pos, val);
  77. update(i, v * 2 + 2, tm + 1, tr, pos, val);
  78. dp[i][v] = min(dp[i][v * 2 + 1], dp[i][v * 2 + 2]);
  79. }
  80.  
  81. signed main() {
  82. seriy();
  83. int n, m;
  84. cin >> n >> m;
  85. vector<pair<int, int>> a(n);
  86. for(int i = 0; i < n; i++) {
  87. cin >> a[i].x >> a[i].y;
  88. }
  89. a.push_back({1, 0});
  90. a.push_back({m, 0});
  91. sort(all(a));
  92. dp.resize(a.size(), vector<int>(4 * (m + 2), INF));
  93. dp[0][0] = 0;
  94. for(int i = 1; i < dp.size(); i++) {
  95. for(int j = 0; j < m + 1; j++) {
  96. int mn = get(i, 0, 0, m, max(a[i].x - a[i - 1].x - j, 0ll), m);
  97. update(i, 0, 0, m, j, mn + max(j - a[i].y, 0ll));
  98. }
  99. }
  100. cout << get(dp.size() - 1, 0, 0, m, 0, 0);
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment