#include <bits/stdc++.h>
#define ll long long
#define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
#define TimeRun {End=clock();cerr<<"Time run: "<<(float)(End-Begin)/CLOCKS_PER_SEC<<"s"<<el;}
#define mem(c, x) memset(c, x, sizeof(c))
#define all(c) c.begin(), c.end()
#define bit(i,j) ((i >> j) & 1)
#define se second
#define fi first
#define el '\n'
using namespace std;
template<class X, class Y> bool maximize(X &a, const Y &b) { return (a < b ? a = b, 1 : 0); }
template<class X, class Y> bool minimize(X &a, const Y &b) { return (a > b ? a = b, 1 : 0); }
int dx[8] = {0, 1, 0,-1, 1, 1,-1,-1};
int dy[8] = {1, 0,-1, 0, 1,-1,-1, 1};
const int maxn = 5e5 + 2;
const int Inf = 2e9 + 7;
const ll Infll = 1e18 + 9;
const ll Mod = 1e9 + 7;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ll st[maxn << 2], lz[maxn << 2], res;
int n;
pair<ll, int> a[maxn];
void down(int id, int l, int r) {
if (!lz[id]) return;
st[id<<1] += lz[id];
lz[id<<1] += lz[id];
st[id<<1|1] += lz[id];
lz[id<<1|1] += lz[id];
lz[id] = 0;
}
void update(int id, int l, int r, int u, int v, ll val) {
if (l > v || u > r) return;
if (u <= l && r <= v) {
st[id] += val;
lz[id] += val;
return;
}
int mid = l + r >> 1;
down(id, l, r);
update(id<<1, l, mid, u, v, val);
update(id<<1|1, mid+1, r, u, v, val);
st[id] = max(st[id<<1], st[id<<1|1]);
}
ll get(int id, int l, int r, int u, int v) {
if (l > v || u > r) return 0;
if (u <= l && r <= v) {
return st[id];
}
int mid = l + r >> 1;
down(id, l, r);
return max(get(id<<1, l, mid, u, v), get(id<<1|1, mid+1, r, u, v));
}
void solve() {
cin >> n;
for (int i=1; i<=n; i++) cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1);
for (int i=1; i<=n; i++) {
update(1, 1, n, i, i, a[i].fi);
update(1, 1, n, 1, i, a[i].se);
maximize(res, get(1, 1, n, 1, i) - a[i].fi);
}
cout << res;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t Begin = clock(), End;
io("task");
solve();
TimeRun; return (0 ^ 0);
}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:4:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
4 | #define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
art.cpp:74:5: note: in expansion of macro 'io'
74 | io("task");
| ^~
art.cpp:4:85: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
4 | #define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
art.cpp:74:5: note: in expansion of macro 'io'
74 | io("task");
| ^~
# | 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... |