#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 5e5 + 5;
const ll INF = 1e18;
ll pre[MAX];
vector<pair<ll, ll>> p;
ll mx [MAX];
ll mn[MAX];
int main(){
fast_io();
int n;
ll ans = -INF;
cin >> n;
f0r(i, n){
ll ai, bi;
cin >> ai >> bi;
ans = max(ans, bi);
p.eb(mp(ai, bi));
}
sort(all(p));
f0r(i, n){
if(i == 0) pre[i] = p[i].s;
else pre[i] = pre[i-1] + p[i].s;
}
vector<ll> v1;
f0r(i, n){
v1.eb(pre[i] - p[i].f);
}
vector<ll> v2;
f0r(i, n){
if(i == 0) v2.eb(-p[i].f);
else v2.eb(pre[i-1] - p[i].f);
}
f0r(i,n){
if(i == 0) mn[i] = v2[i];
else mn[i] = min(mn[i+1], v2[i]);
}
// cout << v1 << " " << v2 << endl;
for(int i = n-1; i>= 0; i--){
if(i == n-1) mx[i] = v1[i];
else mx[i] = max(mx[i+1], v1[i]);
}
// ll ans = 0;
f0r(i, n-1){
ans = max(ans, mx[i+1] - mn[i]);
}
cout << ans << endl;
return 0;
}
Compilation message
art.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
art.cpp: In function 'void io(std::__cxx11::string)':
art.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
art.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
760 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
5 ms |
760 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
36 |
Correct |
5 ms |
760 KB |
Output is correct |
37 |
Correct |
5 ms |
760 KB |
Output is correct |
38 |
Correct |
5 ms |
760 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
760 KB |
Output is correct |
41 |
Correct |
5 ms |
760 KB |
Output is correct |
42 |
Correct |
5 ms |
760 KB |
Output is correct |
43 |
Correct |
5 ms |
760 KB |
Output is correct |
44 |
Correct |
5 ms |
760 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
5 ms |
760 KB |
Output is correct |
47 |
Correct |
5 ms |
764 KB |
Output is correct |
48 |
Correct |
5 ms |
760 KB |
Output is correct |
49 |
Correct |
4 ms |
760 KB |
Output is correct |
50 |
Correct |
5 ms |
760 KB |
Output is correct |
51 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
760 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
5 ms |
760 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
36 |
Correct |
5 ms |
760 KB |
Output is correct |
37 |
Correct |
5 ms |
760 KB |
Output is correct |
38 |
Correct |
5 ms |
760 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
760 KB |
Output is correct |
41 |
Correct |
5 ms |
760 KB |
Output is correct |
42 |
Correct |
5 ms |
760 KB |
Output is correct |
43 |
Correct |
5 ms |
760 KB |
Output is correct |
44 |
Correct |
5 ms |
760 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
5 ms |
760 KB |
Output is correct |
47 |
Correct |
5 ms |
764 KB |
Output is correct |
48 |
Correct |
5 ms |
760 KB |
Output is correct |
49 |
Correct |
4 ms |
760 KB |
Output is correct |
50 |
Correct |
5 ms |
760 KB |
Output is correct |
51 |
Correct |
5 ms |
760 KB |
Output is correct |
52 |
Correct |
284 ms |
31932 KB |
Output is correct |
53 |
Correct |
286 ms |
31796 KB |
Output is correct |
54 |
Correct |
284 ms |
44652 KB |
Output is correct |
55 |
Correct |
284 ms |
44560 KB |
Output is correct |
56 |
Correct |
286 ms |
44504 KB |
Output is correct |
57 |
Correct |
285 ms |
44544 KB |
Output is correct |
58 |
Correct |
286 ms |
44500 KB |
Output is correct |
59 |
Correct |
284 ms |
44632 KB |
Output is correct |
60 |
Correct |
283 ms |
44572 KB |
Output is correct |
61 |
Correct |
286 ms |
44472 KB |
Output is correct |
62 |
Correct |
283 ms |
44512 KB |
Output is correct |
63 |
Correct |
283 ms |
44504 KB |
Output is correct |
64 |
Correct |
283 ms |
44508 KB |
Output is correct |
65 |
Correct |
282 ms |
44628 KB |
Output is correct |
66 |
Correct |
282 ms |
44500 KB |
Output is correct |
67 |
Correct |
291 ms |
40276 KB |
Output is correct |
68 |
Correct |
284 ms |
40248 KB |
Output is correct |