#include #include #include using namespace std; struct interv { double start, end; bool operator>(const struct interv &other) const { if (start != other.start) return start > other.start; return end > other.end; } }; int main() { priority_queue, greater > heap; struct interv help; double len, ans; while (scanf (" %lf", &len) && len > 0) { ans = len; while (scanf (" %lf %lf", &help.start, &help.end) != EOF && help.start <= help.end) { heap.push(help); } help = heap.top(); heap.pop(); while (!heap.empty()) { if (heap.top().start > help.end) { //put it on the vector and ask for more ans -= help.end - help.start; help = heap.top(); } else if (heap.top().end > help.end) { help.end = heap.top().end; } else { } //do nothing, subinterval is inside heap.pop(); } ans -= help.end - help.start; printf("The total planting length is %.1lf\n", ans); } return 0; }