Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ∧_∧
- ( ・ω・。)つ━☆・*。
- ⊂ ノ ・゜
- しーJ Accepted
- */
- // #pragma GCC optimize("O3")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define x first
- #define y second
- #define int long long
- using namespace std;
- using namespace __gnu_pbds;
- typedef long double ld;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(14);
- #ifdef _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int MAXN = 1e6 + 10;
- const int MAXM = 600;
- const int INF = 1e9;
- const int BASE = 47;
- const int MOD = 43200;
- const int MAXLOG = 21;
- vector<vector<int>> dp;
- int get(int i, int v, int tl, int tr, int l, int r) {
- if(tl > r || tr < l) {
- return INF;
- }
- if(tl >+ l && tr <= r) {
- return dp[i][v];
- }
- int tm = (tl + tr) >> 1;
- int left = get(i, v * 2 + 1, tl, tm, l, r);
- int right = get(i, v * 2 + 2, tm + 1, tr, l, r);
- return min(left, right);
- }
- void update(int i, int v, int tl, int tr, int pos, int val) {
- if(tl > pos || tr < pos) {
- return;
- }
- if(tl == tr) {
- dp[i][v] = min(dp[i][v], val);
- return;
- }
- int tm = (tl + tr) >> 1;
- update(i, v * 2 + 1, tl, tm, pos, val);
- update(i, v * 2 + 2, tm + 1, tr, pos, val);
- dp[i][v] = min(dp[i][v * 2 + 1], dp[i][v * 2 + 2]);
- }
- signed main() {
- seriy();
- int n, m;
- cin >> n >> m;
- vector<pair<int, int>> a(n);
- for(int i = 0; i < n; i++) {
- cin >> a[i].x >> a[i].y;
- }
- a.push_back({1, 0});
- a.push_back({m, 0});
- sort(all(a));
- dp.resize(a.size(), vector<int>(4 * (m + 2), INF));
- dp[0][0] = 0;
- for(int i = 1; i < dp.size(); i++) {
- for(int j = 0; j < m + 1; j++) {
- int mn = get(i, 0, 0, m, max(a[i].x - a[i - 1].x - j, 0ll), m);
- update(i, 0, 0, m, j, mn + max(j - a[i].y, 0ll));
- }
- }
- cout << get(dp.size() - 1, 0, 0, m, 0, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment