문제 링크 : 백준 7983번
내일부터 연속으로 쉴 수 있는 최대값을 구하는 것이기 때문에 가장 빠른 제출일에서 얼마나 더 빨리 시작해야하는가를 구하면 된다.
제출일 - 과제하는데 걸리는 일 = 제출일에 과제를 끝내기 위해 과제를 시작해야하는 날(즉, 최대한 쉬다가 과제를 하는 경우).
= now라고 가정
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
vector<pair<int, int>> arr;
bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second>b.second;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i=0 ; i<n ; i++) {
        int a, b;
        cin >> a >> b;
        arr.push_back({a, b});
    }
    sort(arr.begin(), arr.end(), cmp);
    int now=arr[0].second-arr[0].first;
    for(int i=1 ; i<n ; i++) {
        int d=arr[i].first, t=arr[i].second;
        if(now>=t) {
            now = t-d;
        } else {
            now = now-d;
        }
    }
    cout << now;
    
    return 0;
}