Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- pair<int, int> p[n];
- for(int i = 0; i < n; i++) {
- cin >> p[i].first;
- cin >> p[i].second;
- }
- sort(p, p + n);
- long long avtomobili = -1e18;
- long long momentalen_broj = 0;
- for(int i = 0; i < n; i++) {
- if(i == 0) {
- momentalen_broj = p[i].second;
- avtomobili = momentalen_broj;
- }
- else {
- if(momentalen_broj > p[i].second) {
- avtomobili = max(avtomobili, momentalen_broj);
- momentalen_broj = p[i].second;
- }
- else {
- avtomobili += (p[i].second - momentalen_broj);
- momentalen_broj = p[i].second;
- }
- }
- }
- cout << avtomobili << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement