/*-----------------------------
Author : TgX.2
10Ti - K28 - CHV
-----------------------------*/
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a), _b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a), _b=(b);i>=_b;--i)
#define FORC(i,a,b,c) for(int i=(a), _b=(b), _c=(c);i<=_b;i+=_c)
#define FORSq(i,a,b) for(int i=(a), _b=(b);i*i<=_b;++i)
#define FORSt(i,s) for(int i=0, _s=(int)(s.size());i<_s;++i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back()
#define eb emplace_back
#define ers erase
#define ins insert
#define emp empty()
#define rvs reverse
#define BIT(x,i) (((x)>>(i))&1)
#define MASK(i) (1LL<<(i))
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define FIRSTBIT(x) __builtin_ctzll(x)
#define len(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define alln(x,n) (x)+1, (x)+1+(n)
#define _ <<" "<<
#define __ << "\n"
#define ___ << " "
#define ____ << "\t"
#define file "temp"
#define ______________TgX______________ main()
#define int long long
#define intmax 1e9
#define intmin -1e9
#define llongmax 1e18
#define llongmin -1e18
#define memo(a, val) memset((a), (val), sizeof((a)))
using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction
void fastio() {
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
freopen(file".debug", "w", stderr);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
template<typename T1, typename T2> bool mini(T1 &a, T2 b)
{if(a>b) a=b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b)
{if(a<b) a=b; else return 0; return 1;}
/*-----------------------------*/
const int maxn = 5e5 + 7;
int n, dp[maxn];
pii a[maxn];
void process() {
cin >> n;
FOR(i, 1, n)
cin >> a[i].fi >> a[i].se;
sort(alln(a, n));
dp[1] = a[1].se;
int ans = 0;
FOR(i, 1, n)
maxi(ans, dp[i] = max(a[i].se, dp[i - 1] + a[i].se - a[i].fi + a[i - 1].fi));
// FOR(i, 1, n)
// cout << dp[i] __ ;
cout << ans;
}
/*-----------------------------*/
______________TgX______________ {
auto start = high_resolution_clock::now();
fastio();
process();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cerr << "Time: " << duration.count() << " ms" << endl;
}
/*==============================+
|INPUT |
--------------------------------|
================================+
|OUTPUT |
--------------------------------|
===============================*/
Compilation message
art.cpp:41:41: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | #define ______________TgX______________ main()
| ^~~~
art.cpp:105:1: note: in expansion of macro '______________TgX______________'
105 | ______________TgX______________ {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp: In function 'void fastio()':
art.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen(file".debug", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2676 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2648 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2632 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
2 ms |
2648 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
2 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2720 KB |
Output is correct |
46 |
Correct |
2 ms |
2652 KB |
Output is correct |
47 |
Correct |
2 ms |
2664 KB |
Output is correct |
48 |
Correct |
1 ms |
2652 KB |
Output is correct |
49 |
Correct |
2 ms |
2652 KB |
Output is correct |
50 |
Correct |
2 ms |
2652 KB |
Output is correct |
51 |
Correct |
2 ms |
2672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2676 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2648 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2632 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
2 ms |
2648 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
2 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2720 KB |
Output is correct |
46 |
Correct |
2 ms |
2652 KB |
Output is correct |
47 |
Correct |
2 ms |
2664 KB |
Output is correct |
48 |
Correct |
1 ms |
2652 KB |
Output is correct |
49 |
Correct |
2 ms |
2652 KB |
Output is correct |
50 |
Correct |
2 ms |
2652 KB |
Output is correct |
51 |
Correct |
2 ms |
2672 KB |
Output is correct |
52 |
Correct |
141 ms |
24660 KB |
Output is correct |
53 |
Correct |
115 ms |
24656 KB |
Output is correct |
54 |
Correct |
118 ms |
24676 KB |
Output is correct |
55 |
Correct |
114 ms |
24660 KB |
Output is correct |
56 |
Correct |
113 ms |
24684 KB |
Output is correct |
57 |
Correct |
112 ms |
24664 KB |
Output is correct |
58 |
Correct |
119 ms |
24808 KB |
Output is correct |
59 |
Correct |
114 ms |
24656 KB |
Output is correct |
60 |
Correct |
111 ms |
24656 KB |
Output is correct |
61 |
Correct |
114 ms |
24560 KB |
Output is correct |
62 |
Correct |
118 ms |
24796 KB |
Output is correct |
63 |
Correct |
114 ms |
24656 KB |
Output is correct |
64 |
Correct |
126 ms |
24664 KB |
Output is correct |
65 |
Correct |
145 ms |
24812 KB |
Output is correct |
66 |
Correct |
120 ms |
24684 KB |
Output is correct |
67 |
Correct |
124 ms |
24672 KB |
Output is correct |
68 |
Correct |
115 ms |
24656 KB |
Output is correct |