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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
struct Line {
long long x;
long long yl;
long long yh;
bool operator < (Line b) {
return x == b.x ? yl < b.yl : x < b.x;
}
};
int n, starty, endx;
vector<Line> line;
set<pair<long long, long long>> minY;
long long min(long long a, long long b) {
return a < b ? a : b;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> starty >> endx;
for (int i = 0; i < n; i++) {
long long a, b, c;
cin >> a >> b >> c;
line.push_back({ a,b,c });
}
sort(line.begin(), line.end());
minY.insert({ starty, 0 });
for (int i = 0; i < n; i++) {
vector<pair<long long, long long>> temp;
set<pair<long long, long long>>::iterator s = minY.lower_bound({ line[i].yl, -200000000000000 });
set<pair<long long, long long>>::iterator e = minY.upper_bound({ line[i].yh, 200000000000000 });
long long up = 20000000000000, down = 200000000000000;
for (set<pair<long long, long long>>::iterator j = s; j != e; ++j) {
up = min(up, (line[i].yh - j->first) + j->second);
down = min(down, (j->first - line[i].yl) + j->second);
}
minY.erase(s, e);
minY.insert({ line[i].yh, up });
minY.insert({ line[i].yl, down });
}
long long result = 20000000000000;
vector<int> resultY;
for (set<pair<long long, long long>>::iterator s = minY.begin(); s != minY.end(); s++) {
result = min(result, s->second);
}
for (set<pair<long long, long long>>::iterator s = minY.begin(); s != minY.end(); s++) {
if (result == s->second) {
resultY.push_back(s->first);
}
}
cout << result + endx<< "\n";
cout << resultY.size() << " ";
for (int i = 0; i < resultY.size(); i++) {
cout << resultY[i] << " ";
}
}
|