#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <limits.h>
#include <list>
#include <cmath>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
using namespace std;
#define int long long
#define MOD 1000000007
#define INF 2000000000
#define IN 100001
#define LOG 20
#define MINF -2000000000
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(nullptr);
void solution(){
int n; cin >> n;
vector<pair<int, int> > arr;
arr.push_back({0,0});
for(int i = 0; i < n; i++){
int a,b; cin >> a >> b;
arr.push_back({a,b});
}
sort(all(arr));
vector<int> pre(n+1);
pre[1] = arr[1].second;
for(int i = 2; i <= n; i++){
pre[i] = pre[i-1] + arr[i].second;
}
int ans = -1;
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
ans = max(ans , (pre[j] - pre[i-1]) - (arr[j].first - arr[i].first) );
}
}
cout << ans << endl;
}
signed main() {
fast_io
int t = 1;
//cin >> t;
while (t--) {
solution();
}
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... |