Submission #1089993

# Submission time Handle Problem Language Result Execution time Memory
1089993 2024-09-17T13:49:16 Z HienTD Art Exhibition (JOI18_art) C++14
100 / 100
148 ms 20948 KB
#include <bits/stdc++.h>
using namespace std;

//#define LOCAL

#define          	fi  first
#define             se  second
#define           TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define         ALL(v)  (v).begin(), (v).end()
#define  		BIT(x)  (1LL << (x))
#define 	MASK(x, i)  (((x) >> (i)) & 1)
#define   FOR(i, a, b)  for(int i = (a), _b = (b); i <= _b; ++ i)
#define  FORD(i, b, a)  for(int i = (b), _a = (a); i >= _a; -- i)

const string NAME = "BAITAP";

const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int mod = 998244353;

const int mxN = 5e5 + 5;

int N;
vector<pair<long long, long long>> A(mxN);

void init(void){
	cin >> N;
	FOR(i, 1, N) cin >> A[i].fi >> A[i].se;
}

struct cmp{
	bool operator() (const pair<long long, long long> &a, const pair<long long, long long> &b){
		return a.fi != b.fi ? a.fi < b.fi : a.se > b.se;
	}
};

void process(void){
	sort(A.begin() + 1, A.begin() + 1 + N, cmp());
	long long ans = -INF;
	long long mx = -INF;
	FOR(i, 1, N){
		A[i].se += A[i - 1].se;
		mx = max(A[i].fi - A[i - 1].se, mx);
		ans = max(ans, A[i].se - A[i].fi + mx);
	}
	cout << ans;
}

signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	#ifdef LOCAL
		freopen((NAME + ".INP").c_str(), "r", stdin);
		freopen((NAME + ".OUT").c_str(), "w", stdout);
	#endif // I/O

	init();
	process();
	cerr << "\nTime elapsed: " << TIME << "s.\n";
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8092 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8076 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8092 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8076 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8068 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 4 ms 8280 KB Output is correct
16 Correct 5 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8288 KB Output is correct
21 Correct 3 ms 8288 KB Output is correct
22 Correct 3 ms 8284 KB Output is correct
23 Correct 3 ms 8180 KB Output is correct
24 Correct 3 ms 8280 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8092 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8076 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8068 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 4 ms 8280 KB Output is correct
16 Correct 5 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8288 KB Output is correct
21 Correct 3 ms 8288 KB Output is correct
22 Correct 3 ms 8284 KB Output is correct
23 Correct 3 ms 8180 KB Output is correct
24 Correct 3 ms 8280 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 3 ms 8284 KB Output is correct
27 Correct 4 ms 8284 KB Output is correct
28 Correct 4 ms 8284 KB Output is correct
29 Correct 4 ms 8284 KB Output is correct
30 Correct 6 ms 8284 KB Output is correct
31 Correct 4 ms 8288 KB Output is correct
32 Correct 4 ms 8284 KB Output is correct
33 Correct 4 ms 8284 KB Output is correct
34 Correct 4 ms 8280 KB Output is correct
35 Correct 5 ms 8284 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 4 ms 8540 KB Output is correct
38 Correct 7 ms 8284 KB Output is correct
39 Correct 4 ms 8412 KB Output is correct
40 Correct 4 ms 8304 KB Output is correct
41 Correct 4 ms 8288 KB Output is correct
42 Correct 5 ms 8284 KB Output is correct
43 Correct 4 ms 8432 KB Output is correct
44 Correct 4 ms 8284 KB Output is correct
45 Correct 4 ms 8284 KB Output is correct
46 Correct 5 ms 8284 KB Output is correct
47 Correct 5 ms 8284 KB Output is correct
48 Correct 6 ms 8284 KB Output is correct
49 Correct 4 ms 8356 KB Output is correct
50 Correct 4 ms 8284 KB Output is correct
51 Correct 4 ms 8252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8092 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8076 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8068 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 4 ms 8280 KB Output is correct
16 Correct 5 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 3 ms 8288 KB Output is correct
21 Correct 3 ms 8288 KB Output is correct
22 Correct 3 ms 8284 KB Output is correct
23 Correct 3 ms 8180 KB Output is correct
24 Correct 3 ms 8280 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 3 ms 8284 KB Output is correct
27 Correct 4 ms 8284 KB Output is correct
28 Correct 4 ms 8284 KB Output is correct
29 Correct 4 ms 8284 KB Output is correct
30 Correct 6 ms 8284 KB Output is correct
31 Correct 4 ms 8288 KB Output is correct
32 Correct 4 ms 8284 KB Output is correct
33 Correct 4 ms 8284 KB Output is correct
34 Correct 4 ms 8280 KB Output is correct
35 Correct 5 ms 8284 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 4 ms 8540 KB Output is correct
38 Correct 7 ms 8284 KB Output is correct
39 Correct 4 ms 8412 KB Output is correct
40 Correct 4 ms 8304 KB Output is correct
41 Correct 4 ms 8288 KB Output is correct
42 Correct 5 ms 8284 KB Output is correct
43 Correct 4 ms 8432 KB Output is correct
44 Correct 4 ms 8284 KB Output is correct
45 Correct 4 ms 8284 KB Output is correct
46 Correct 5 ms 8284 KB Output is correct
47 Correct 5 ms 8284 KB Output is correct
48 Correct 6 ms 8284 KB Output is correct
49 Correct 4 ms 8356 KB Output is correct
50 Correct 4 ms 8284 KB Output is correct
51 Correct 4 ms 8252 KB Output is correct
52 Correct 123 ms 20804 KB Output is correct
53 Correct 148 ms 20672 KB Output is correct
54 Correct 122 ms 20820 KB Output is correct
55 Correct 128 ms 20808 KB Output is correct
56 Correct 128 ms 20820 KB Output is correct
57 Correct 122 ms 20820 KB Output is correct
58 Correct 127 ms 20688 KB Output is correct
59 Correct 131 ms 20808 KB Output is correct
60 Correct 123 ms 20948 KB Output is correct
61 Correct 125 ms 20560 KB Output is correct
62 Correct 125 ms 20820 KB Output is correct
63 Correct 125 ms 20816 KB Output is correct
64 Correct 120 ms 20684 KB Output is correct
65 Correct 120 ms 20816 KB Output is correct
66 Correct 120 ms 20672 KB Output is correct
67 Correct 119 ms 20804 KB Output is correct
68 Correct 120 ms 20684 KB Output is correct