-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathe.cc
More file actions
30 lines (28 loc) · 666 Bytes
/
e.cc
File metadata and controls
30 lines (28 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// https://codeforces.com/contest/1253/problem/E
#include <bits/stdc++.h>
using namespace std;
using ii = tuple<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
int main() {
int n, m, x, s, l, r;
cin >> n >> m;
vii a(n);
for (int i = 0; i < n; i++) {
cin >> x >> s;
a[i] = { x - s, x + s };
}
vi dp(m + 1);
for (int i = 0; i <= m; i++) dp[i] = i;
for (int i = 1; i <= m; i++) {
for (int j = 0; j < n; j++) {
tie(l, r) = a[j];
if (l <= i && i <= r) dp[i] = dp[i - 1];
else if (r < i) {
int c = i - r;
dp[i] = min(dp[i], dp[max(0, l - c - 1)] + c);
}
}
}
cout << dp[m] << '\n';
}