//#include "shoes.h"
#include <bits/stdc++.h>
#define respagold ios_base::sync_with_stdio(0), cin.tie(0);
#define int long long
#define ll long long
#define int2 __int128_t
#define FOR( i, x, n, d ) for( int i = x; i <= n; i += d )
#define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d )
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define pii pair <int, int>
using namespace std;
const int N = 1e6 + 12;
const int mod = 1e9 + 7;
const ll inf = 2e18;
int n, m, x, y, a[N], b[N], p[N];
vector <pii> v;
void solve()
{
cin >> n;
x = inf, y = 0;
FOR( i, 1, n, 1 )
{
cin >> a[i] >> b[i];
v.pb({a[i], b[i]});
}
sort( all(v) );
FOR( i, 1, n, 1 )
{
p[i] = p[i - 1] + v[i - 1].S;
}
FOR( i, 1, n, 1 )
{
x = min(x, p[i - 1] - v[i - 1].F);
y = max(y, p[i] - v[i - 1].F - x);
}
cout << y << '\n';
}
signed main()
{
respagold;
int test = 1;
if( !test ) cin >> test;
while( test -- ) solve();
}
# | 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... |