답안 #66146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66146 2018-08-09T21:29:02 Z pamaj Art Exhibition (JOI18_art) C++14
100 / 100
313 ms 223932 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
typedef long long ll;

int n;

ll k[maxn], p[maxn];

struct obj
{
	ll val, size;
} it[maxn];

bool compara(obj a, obj b)
{
	if(a.size == b.size) return a.val < b.val;
	return a.size < b.size;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr);

	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> it[i].size >> it[i].val;
	}

	sort(it + 1, it + n + 1, compara);

	for(int i = 1; i <= n; i++)
	{
		p[i] = it[i].val + p[i - 1]; 
	}

	k[n] = p[n]-it[n].size;

	for(int i = n-1; i >= 1; i--)
	{
		k[i] = max(k[i + 1], p[i] - it[i].size);
	}


	ll ans = 0;
	for(int i = 1; i < n; i++)
	{
		ans = max(ans, it[i].size - p[i - 1] + k[i]);
	}


	cout << ans << "\n";


	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 3 ms 700 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 3 ms 700 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 788 KB Output is correct
15 Correct 2 ms 800 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 868 KB Output is correct
21 Correct 2 ms 1080 KB Output is correct
22 Correct 2 ms 1080 KB Output is correct
23 Correct 2 ms 1080 KB Output is correct
24 Correct 2 ms 1080 KB Output is correct
25 Correct 3 ms 1080 KB Output is correct
26 Correct 2 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 3 ms 700 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 788 KB Output is correct
15 Correct 2 ms 800 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 868 KB Output is correct
21 Correct 2 ms 1080 KB Output is correct
22 Correct 2 ms 1080 KB Output is correct
23 Correct 2 ms 1080 KB Output is correct
24 Correct 2 ms 1080 KB Output is correct
25 Correct 3 ms 1080 KB Output is correct
26 Correct 2 ms 1080 KB Output is correct
27 Correct 4 ms 1196 KB Output is correct
28 Correct 5 ms 1336 KB Output is correct
29 Correct 5 ms 1452 KB Output is correct
30 Correct 6 ms 1644 KB Output is correct
31 Correct 4 ms 1708 KB Output is correct
32 Correct 5 ms 1900 KB Output is correct
33 Correct 4 ms 1964 KB Output is correct
34 Correct 6 ms 2096 KB Output is correct
35 Correct 5 ms 2224 KB Output is correct
36 Correct 5 ms 2360 KB Output is correct
37 Correct 8 ms 2480 KB Output is correct
38 Correct 4 ms 2672 KB Output is correct
39 Correct 6 ms 2672 KB Output is correct
40 Correct 5 ms 2868 KB Output is correct
41 Correct 6 ms 2992 KB Output is correct
42 Correct 6 ms 3168 KB Output is correct
43 Correct 6 ms 3244 KB Output is correct
44 Correct 5 ms 3372 KB Output is correct
45 Correct 6 ms 3632 KB Output is correct
46 Correct 6 ms 3648 KB Output is correct
47 Correct 5 ms 3772 KB Output is correct
48 Correct 5 ms 3900 KB Output is correct
49 Correct 5 ms 4028 KB Output is correct
50 Correct 4 ms 4156 KB Output is correct
51 Correct 4 ms 4412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 3 ms 700 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 788 KB Output is correct
15 Correct 2 ms 800 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 868 KB Output is correct
21 Correct 2 ms 1080 KB Output is correct
22 Correct 2 ms 1080 KB Output is correct
23 Correct 2 ms 1080 KB Output is correct
24 Correct 2 ms 1080 KB Output is correct
25 Correct 3 ms 1080 KB Output is correct
26 Correct 2 ms 1080 KB Output is correct
27 Correct 4 ms 1196 KB Output is correct
28 Correct 5 ms 1336 KB Output is correct
29 Correct 5 ms 1452 KB Output is correct
30 Correct 6 ms 1644 KB Output is correct
31 Correct 4 ms 1708 KB Output is correct
32 Correct 5 ms 1900 KB Output is correct
33 Correct 4 ms 1964 KB Output is correct
34 Correct 6 ms 2096 KB Output is correct
35 Correct 5 ms 2224 KB Output is correct
36 Correct 5 ms 2360 KB Output is correct
37 Correct 8 ms 2480 KB Output is correct
38 Correct 4 ms 2672 KB Output is correct
39 Correct 6 ms 2672 KB Output is correct
40 Correct 5 ms 2868 KB Output is correct
41 Correct 6 ms 2992 KB Output is correct
42 Correct 6 ms 3168 KB Output is correct
43 Correct 6 ms 3244 KB Output is correct
44 Correct 5 ms 3372 KB Output is correct
45 Correct 6 ms 3632 KB Output is correct
46 Correct 6 ms 3648 KB Output is correct
47 Correct 5 ms 3772 KB Output is correct
48 Correct 5 ms 3900 KB Output is correct
49 Correct 5 ms 4028 KB Output is correct
50 Correct 4 ms 4156 KB Output is correct
51 Correct 4 ms 4412 KB Output is correct
52 Correct 252 ms 32328 KB Output is correct
53 Correct 253 ms 45064 KB Output is correct
54 Correct 262 ms 57980 KB Output is correct
55 Correct 273 ms 70528 KB Output is correct
56 Correct 279 ms 83096 KB Output is correct
57 Correct 278 ms 95864 KB Output is correct
58 Correct 294 ms 108540 KB Output is correct
59 Correct 302 ms 121092 KB Output is correct
60 Correct 282 ms 133964 KB Output is correct
61 Correct 259 ms 145504 KB Output is correct
62 Correct 262 ms 156800 KB Output is correct
63 Correct 265 ms 168440 KB Output is correct
64 Correct 266 ms 179604 KB Output is correct
65 Correct 288 ms 191584 KB Output is correct
66 Correct 279 ms 201848 KB Output is correct
67 Correct 300 ms 212684 KB Output is correct
68 Correct 313 ms 223932 KB Output is correct