/** * Buggy Robot: solution by Pacific Northwest Regional authoring team */ #include #include #include #include using namespace std ; int main() { int N ; cin >> N ; vector> intvl(N) ; map dp ; for (int i=0; i> intvl[i].second >> intvl[i].first ; sort(intvl.begin(), intvl.end()) ; for (auto gap : intvl) { auto it = dp.upper_bound(gap.second) ; long long tot = gap.first - gap.second ; if (it != dp.begin()) tot += (--it)->second ; if (dp.size() == 0 || tot > dp.rbegin()->second) dp[gap.first] = tot ; } cout << dp.rbegin()->second << endl ; }