This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
    
    long long n,a,b;
    cin >> n;
    
    vector<pair<long long, long long>> tab(0);
    
    for (int i=0; i<n; i++){
        cin >> a >> b;
        tab.push_back({a,b});
    }
    
    sort(tab.begin(),tab.end());
    
    long long wynik = 0;
    for (int i=0; i<n; i++){
        long long akt_wynik = 0;
        long long pop = tab[i].first;
        for (int j=i; j<n; j++){
            //cout << tab[j].first << " " << pop << tab[j].second << " " << akt_wynik << " " << wynik << endl;
            akt_wynik = akt_wynik-(tab[j].first-pop)+tab[j].second;
            pop = tab[j].first;
            wynik = max(wynik,akt_wynik);
        }
    }
    
    cout << wynik << endl;
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |