Submission #530105

# Submission time Handle Problem Language Result Execution time Memory
530105 2022-02-24T15:35:52 Z buidangnguyen05 Art Exhibition (JOI18_art) C++14
100 / 100
188 ms 28736 KB
/* input

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 5e5 + 10;
ll pref[N], mx[N];
pair<ll, int> a[N];

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	if (fopen("task.inp", "r")) {
		freopen("task.inp", "r", stdin);
		freopen("task.out", "w", stdout);
	}

	int n; cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
	
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i].second;
	
	memset(mx, -127, sizeof(mx));
	for (int i = n; i; --i) mx[i] = max(mx[i + 1], pref[i] - a[i].first);
	ll res = 0;
	for (int i = 1; i <= n; ++i) res = max(res, a[i].first - pref[i - 1] + mx[i]);

	cout << res;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:16:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   freopen("task.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:17:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   freopen("task.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4152 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4160 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4152 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 2 ms 4168 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4152 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4160 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4152 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 2 ms 4168 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 2 ms 4172 KB Output is correct
13 Correct 2 ms 4172 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4172 KB Output is correct
20 Correct 2 ms 4172 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4172 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4152 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4160 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4152 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 2 ms 4168 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 2 ms 4172 KB Output is correct
13 Correct 2 ms 4172 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4172 KB Output is correct
20 Correct 2 ms 4172 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4172 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 4 ms 4408 KB Output is correct
28 Correct 4 ms 4444 KB Output is correct
29 Correct 3 ms 4476 KB Output is correct
30 Correct 3 ms 4428 KB Output is correct
31 Correct 5 ms 4444 KB Output is correct
32 Correct 4 ms 4432 KB Output is correct
33 Correct 4 ms 4484 KB Output is correct
34 Correct 4 ms 4396 KB Output is correct
35 Correct 4 ms 4428 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 4 ms 4432 KB Output is correct
38 Correct 4 ms 4428 KB Output is correct
39 Correct 3 ms 4436 KB Output is correct
40 Correct 4 ms 4436 KB Output is correct
41 Correct 3 ms 4428 KB Output is correct
42 Correct 4 ms 4428 KB Output is correct
43 Correct 4 ms 4408 KB Output is correct
44 Correct 4 ms 4428 KB Output is correct
45 Correct 4 ms 4428 KB Output is correct
46 Correct 4 ms 4412 KB Output is correct
47 Correct 4 ms 4404 KB Output is correct
48 Correct 3 ms 4428 KB Output is correct
49 Correct 4 ms 4428 KB Output is correct
50 Correct 4 ms 4364 KB Output is correct
51 Correct 4 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4152 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4160 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4152 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 2 ms 4168 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 2 ms 4172 KB Output is correct
13 Correct 2 ms 4172 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4172 KB Output is correct
20 Correct 2 ms 4172 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4172 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 4 ms 4408 KB Output is correct
28 Correct 4 ms 4444 KB Output is correct
29 Correct 3 ms 4476 KB Output is correct
30 Correct 3 ms 4428 KB Output is correct
31 Correct 5 ms 4444 KB Output is correct
32 Correct 4 ms 4432 KB Output is correct
33 Correct 4 ms 4484 KB Output is correct
34 Correct 4 ms 4396 KB Output is correct
35 Correct 4 ms 4428 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 4 ms 4432 KB Output is correct
38 Correct 4 ms 4428 KB Output is correct
39 Correct 3 ms 4436 KB Output is correct
40 Correct 4 ms 4436 KB Output is correct
41 Correct 3 ms 4428 KB Output is correct
42 Correct 4 ms 4428 KB Output is correct
43 Correct 4 ms 4408 KB Output is correct
44 Correct 4 ms 4428 KB Output is correct
45 Correct 4 ms 4428 KB Output is correct
46 Correct 4 ms 4412 KB Output is correct
47 Correct 4 ms 4404 KB Output is correct
48 Correct 3 ms 4428 KB Output is correct
49 Correct 4 ms 4428 KB Output is correct
50 Correct 4 ms 4364 KB Output is correct
51 Correct 4 ms 4440 KB Output is correct
52 Correct 165 ms 28552 KB Output is correct
53 Correct 172 ms 28616 KB Output is correct
54 Correct 170 ms 28544 KB Output is correct
55 Correct 188 ms 28616 KB Output is correct
56 Correct 168 ms 28736 KB Output is correct
57 Correct 164 ms 28564 KB Output is correct
58 Correct 171 ms 28532 KB Output is correct
59 Correct 174 ms 28548 KB Output is correct
60 Correct 169 ms 28524 KB Output is correct
61 Correct 172 ms 28392 KB Output is correct
62 Correct 165 ms 28612 KB Output is correct
63 Correct 169 ms 28532 KB Output is correct
64 Correct 170 ms 28548 KB Output is correct
65 Correct 180 ms 28616 KB Output is correct
66 Correct 169 ms 28616 KB Output is correct
67 Correct 182 ms 28568 KB Output is correct
68 Correct 169 ms 28532 KB Output is correct