Submission #795518

# Submission time Handle Problem Language Result Execution time Memory
795518 2023-07-27T10:48:40 Z Mohammed_Atalah Art Exhibition (JOI18_art) C++17
100 / 100
627 ms 67880 KB
/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User

#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;

// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}

// cout << fixed;
// cout << setprecision(4);


// ---------(^_^)--------- //




void main_solve() {

	int n; cin >> n;

	vector<vector<int>> v;
	for (int i = 0 ; i < n; i ++) {
		int a, b; cin >> a >> b;
		v.push_back({a, b});
	}

	sort(v.begin(), v.end());
	vector<int> pre;
	pre.push_back(0);

	for (int i = 0 ; i < n; i ++) {
		pre.push_back(pre[i] + v[i][1]);
	}

	multiset<int> s;
	for (int i = n - 1; i >= 0;  i --) {
		s.insert(pre[n] - pre[i] + v[i][0]);
	}

	int result = 0;
	for (int i = n - 1; i >= 0;  i --) {
		auto it = s.end();
		it--;

		int e = (*it - (pre[n] - pre[i + 1])) - v[i][0];
		result = max(e, result);
		s.erase(s.lower_bound(pre[n] - pre[i] + v[i][0]));
	}
	cout << result << endl;

}


int32_t main() {

	fast;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	// Just another problem (-_-)

	int t;
	t = 1;
	// cin >> t;

	while (t--) {
		main_solve();
	}


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 4 ms 980 KB Output is correct
28 Correct 3 ms 968 KB Output is correct
29 Correct 3 ms 980 KB Output is correct
30 Correct 3 ms 980 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 3 ms 980 KB Output is correct
33 Correct 4 ms 980 KB Output is correct
34 Correct 6 ms 900 KB Output is correct
35 Correct 4 ms 980 KB Output is correct
36 Correct 4 ms 980 KB Output is correct
37 Correct 4 ms 980 KB Output is correct
38 Correct 3 ms 980 KB Output is correct
39 Correct 3 ms 980 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 3 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 3 ms 976 KB Output is correct
44 Correct 4 ms 896 KB Output is correct
45 Correct 4 ms 980 KB Output is correct
46 Correct 3 ms 980 KB Output is correct
47 Correct 3 ms 980 KB Output is correct
48 Correct 4 ms 980 KB Output is correct
49 Correct 4 ms 980 KB Output is correct
50 Correct 5 ms 944 KB Output is correct
51 Correct 4 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 4 ms 980 KB Output is correct
28 Correct 3 ms 968 KB Output is correct
29 Correct 3 ms 980 KB Output is correct
30 Correct 3 ms 980 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 3 ms 980 KB Output is correct
33 Correct 4 ms 980 KB Output is correct
34 Correct 6 ms 900 KB Output is correct
35 Correct 4 ms 980 KB Output is correct
36 Correct 4 ms 980 KB Output is correct
37 Correct 4 ms 980 KB Output is correct
38 Correct 3 ms 980 KB Output is correct
39 Correct 3 ms 980 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 3 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 3 ms 976 KB Output is correct
44 Correct 4 ms 896 KB Output is correct
45 Correct 4 ms 980 KB Output is correct
46 Correct 3 ms 980 KB Output is correct
47 Correct 3 ms 980 KB Output is correct
48 Correct 4 ms 980 KB Output is correct
49 Correct 4 ms 980 KB Output is correct
50 Correct 5 ms 944 KB Output is correct
51 Correct 4 ms 980 KB Output is correct
52 Correct 459 ms 55832 KB Output is correct
53 Correct 567 ms 67760 KB Output is correct
54 Correct 565 ms 67760 KB Output is correct
55 Correct 566 ms 67760 KB Output is correct
56 Correct 600 ms 67760 KB Output is correct
57 Correct 627 ms 67764 KB Output is correct
58 Correct 605 ms 67716 KB Output is correct
59 Correct 553 ms 67760 KB Output is correct
60 Correct 472 ms 67628 KB Output is correct
61 Correct 507 ms 67628 KB Output is correct
62 Correct 447 ms 67736 KB Output is correct
63 Correct 508 ms 67792 KB Output is correct
64 Correct 526 ms 67800 KB Output is correct
65 Correct 453 ms 67880 KB Output is correct
66 Correct 455 ms 67756 KB Output is correct
67 Correct 497 ms 67664 KB Output is correct
68 Correct 487 ms 67676 KB Output is correct