Submission #753470

# Submission time Handle Problem Language Result Execution time Memory
753470 2023-06-05T09:37:30 Z IvanJ Art Exhibition (JOI18_art) C++17
100 / 100
223 ms 32676 KB
#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5e5 + 5;

int n;
ll c[maxn];
ll pref[maxn];
ll maxi[maxn];

int main() {
	scanf("%d", &n);
	vector<pair<ll, int>> v;
	for(int i = 0;i < n;i++) {
		ll a;int b;
		scanf("%lld%d", &a, &b);
		v.pb({a, b});	
	}
	
	sort(all(v));
	for(int i = 0;i < n;i++) {
		c[i] = (ll)v[i].y - v[i].x;
		if(i) c[i] += v[i - 1].x;
		else c[i] += v[i].x;
	}
	
	pref[0] = c[0];
	for(int i = 1;i < n;i++)
		pref[i] = pref[i - 1] + c[i];
	
	maxi[n - 1] = pref[n - 1];
	for(int i = n - 2;i >= 0;i--) 
		maxi[i] = max(maxi[i + 1], pref[i]);
	
	ll ans = 0;
	for(int i = 0;i < n;i++) {
		ll sol = maxi[i];
		if(i) sol -= pref[i - 1];
		if(i) sol += v[i].x - v[i - 1].x;
		ans = max(ans, sol);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
art.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%lld%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# 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 304 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 312 KB Output is correct
7 Correct 1 ms 308 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 308 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 304 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 312 KB Output is correct
7 Correct 1 ms 308 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 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 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 340 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 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 312 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 340 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 304 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 312 KB Output is correct
7 Correct 1 ms 308 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 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 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 340 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 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 312 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 340 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 2 ms 708 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 700 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 724 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 3 ms 708 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 680 KB Output is correct
38 Correct 3 ms 768 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 4 ms 688 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 3 ms 776 KB Output is correct
47 Correct 3 ms 768 KB Output is correct
48 Correct 3 ms 688 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 684 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 304 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 312 KB Output is correct
7 Correct 1 ms 308 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 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 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 340 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 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 312 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 340 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 2 ms 708 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 700 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 724 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 3 ms 708 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 680 KB Output is correct
38 Correct 3 ms 768 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 4 ms 688 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 3 ms 776 KB Output is correct
47 Correct 3 ms 768 KB Output is correct
48 Correct 3 ms 688 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 684 KB Output is correct
52 Correct 223 ms 32560 KB Output is correct
53 Correct 211 ms 32528 KB Output is correct
54 Correct 215 ms 32548 KB Output is correct
55 Correct 195 ms 32584 KB Output is correct
56 Correct 199 ms 32556 KB Output is correct
57 Correct 212 ms 32676 KB Output is correct
58 Correct 197 ms 32652 KB Output is correct
59 Correct 203 ms 32556 KB Output is correct
60 Correct 195 ms 32632 KB Output is correct
61 Correct 207 ms 32452 KB Output is correct
62 Correct 190 ms 32584 KB Output is correct
63 Correct 195 ms 32536 KB Output is correct
64 Correct 203 ms 32604 KB Output is correct
65 Correct 196 ms 32548 KB Output is correct
66 Correct 198 ms 32656 KB Output is correct
67 Correct 204 ms 32544 KB Output is correct
68 Correct 202 ms 32548 KB Output is correct