답안 #42289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42289 2018-02-25T13:02:12 Z RezwanArefin01 Art Exhibition (JOI18_art) C++14
100 / 100
707 ms 16612 KB
#include <bits/stdc++.h>
using namespace std;

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

const int maxn = 5e5 + 10;
ll a[maxn], p[maxn]; 

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	int n; cin >> n; 
	vector<pair<ll, ll> > x(n); 
	for(int i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second; 
	}
	sort(x.begin(), x.end());

	for(int i = 0; i < n; i++) {
		a[i] = x[i].first; 
	} 

	p[0] = x[0].second;
	for(int i = 1; i < n; i++)
		p[i] = p[i - 1] + x[i].second;

	// p[i] - p[j - 1] - a[i] + a[j]
	//=p[i] - a[i] + (a[j] - p[j - 1])

	ll ans = p[0] - a[0], Max = a[0];
	for(int i = 1; i < n; i++) {
		Max = max(Max, a[i] - p[i - 1]);
		ans = max(ans, p[i] - a[i] + Max); 
	} 
	cout << ans << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 736 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 736 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 8 ms 748 KB Output is correct
28 Correct 7 ms 748 KB Output is correct
29 Correct 7 ms 748 KB Output is correct
30 Correct 12 ms 748 KB Output is correct
31 Correct 8 ms 748 KB Output is correct
32 Correct 9 ms 748 KB Output is correct
33 Correct 7 ms 748 KB Output is correct
34 Correct 8 ms 748 KB Output is correct
35 Correct 12 ms 748 KB Output is correct
36 Correct 12 ms 748 KB Output is correct
37 Correct 12 ms 752 KB Output is correct
38 Correct 10 ms 752 KB Output is correct
39 Correct 7 ms 752 KB Output is correct
40 Correct 7 ms 752 KB Output is correct
41 Correct 7 ms 876 KB Output is correct
42 Correct 8 ms 876 KB Output is correct
43 Correct 8 ms 876 KB Output is correct
44 Correct 7 ms 876 KB Output is correct
45 Correct 8 ms 876 KB Output is correct
46 Correct 8 ms 876 KB Output is correct
47 Correct 7 ms 876 KB Output is correct
48 Correct 7 ms 876 KB Output is correct
49 Correct 10 ms 876 KB Output is correct
50 Correct 8 ms 876 KB Output is correct
51 Correct 8 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 736 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 736 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 8 ms 748 KB Output is correct
28 Correct 7 ms 748 KB Output is correct
29 Correct 7 ms 748 KB Output is correct
30 Correct 12 ms 748 KB Output is correct
31 Correct 8 ms 748 KB Output is correct
32 Correct 9 ms 748 KB Output is correct
33 Correct 7 ms 748 KB Output is correct
34 Correct 8 ms 748 KB Output is correct
35 Correct 12 ms 748 KB Output is correct
36 Correct 12 ms 748 KB Output is correct
37 Correct 12 ms 752 KB Output is correct
38 Correct 10 ms 752 KB Output is correct
39 Correct 7 ms 752 KB Output is correct
40 Correct 7 ms 752 KB Output is correct
41 Correct 7 ms 876 KB Output is correct
42 Correct 8 ms 876 KB Output is correct
43 Correct 8 ms 876 KB Output is correct
44 Correct 7 ms 876 KB Output is correct
45 Correct 8 ms 876 KB Output is correct
46 Correct 8 ms 876 KB Output is correct
47 Correct 7 ms 876 KB Output is correct
48 Correct 7 ms 876 KB Output is correct
49 Correct 10 ms 876 KB Output is correct
50 Correct 8 ms 876 KB Output is correct
51 Correct 8 ms 876 KB Output is correct
52 Correct 637 ms 16364 KB Output is correct
53 Correct 621 ms 16364 KB Output is correct
54 Correct 697 ms 16364 KB Output is correct
55 Correct 657 ms 16364 KB Output is correct
56 Correct 646 ms 16364 KB Output is correct
57 Correct 657 ms 16492 KB Output is correct
58 Correct 707 ms 16492 KB Output is correct
59 Correct 654 ms 16492 KB Output is correct
60 Correct 630 ms 16508 KB Output is correct
61 Correct 628 ms 16508 KB Output is correct
62 Correct 673 ms 16508 KB Output is correct
63 Correct 628 ms 16508 KB Output is correct
64 Correct 622 ms 16612 KB Output is correct
65 Correct 619 ms 16612 KB Output is correct
66 Correct 653 ms 16612 KB Output is correct
67 Correct 626 ms 16612 KB Output is correct
68 Correct 697 ms 16612 KB Output is correct