답안 #208775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208775 2020-03-12T07:21:04 Z Siberian Art Exhibition (JOI18_art) C++14
100 / 100
243 ms 24924 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

struct item{
	ll a;
	int b;
	item() {}
	item(ll _a, int _b) {
		a = _a, b = _b;
	}
};

bool operator<(const item & a, const item & b) {
	return tie(a.a, a.b) < tie(b.a, b.b);
}

int n;
vector<item> a;

void read() {
	cin >> n;
	a.resize(n);
	for (auto &i : a) {
		cin >> i.a >> i.b;
	}
	sort(all(a));
}

vector<ll> pref;

void build () {
	pref.resize(n);
	for (int i = 0; i < n; i++) {
		pref[i] = a[i].b;
		if (i > 0) pref[i] += pref[i - 1];
	}
}

ll ans;

void run() {
	/*cout << "a = " << endl;
	for (auto i : a)
		cout << i.a << " " << i.b << endl;*/
	build();
	ans = 0;
	ll min_val = 0;
	for (int i = 0; i < n; i++) {
		chkmin(min_val, (i > 0 ? pref[i - 1] : 0) - a[i].a);
		chkmax(ans, pref[i] - a[i].a - min_val);
	}
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 9 ms 632 KB Output is correct
28 Correct 7 ms 632 KB Output is correct
29 Correct 7 ms 504 KB Output is correct
30 Correct 7 ms 504 KB Output is correct
31 Correct 7 ms 632 KB Output is correct
32 Correct 7 ms 504 KB Output is correct
33 Correct 7 ms 508 KB Output is correct
34 Correct 7 ms 632 KB Output is correct
35 Correct 7 ms 504 KB Output is correct
36 Correct 7 ms 508 KB Output is correct
37 Correct 7 ms 632 KB Output is correct
38 Correct 7 ms 504 KB Output is correct
39 Correct 7 ms 504 KB Output is correct
40 Correct 7 ms 504 KB Output is correct
41 Correct 7 ms 632 KB Output is correct
42 Correct 7 ms 504 KB Output is correct
43 Correct 7 ms 504 KB Output is correct
44 Correct 7 ms 632 KB Output is correct
45 Correct 7 ms 504 KB Output is correct
46 Correct 7 ms 504 KB Output is correct
47 Correct 7 ms 632 KB Output is correct
48 Correct 7 ms 504 KB Output is correct
49 Correct 7 ms 504 KB Output is correct
50 Correct 7 ms 504 KB Output is correct
51 Correct 7 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 9 ms 632 KB Output is correct
28 Correct 7 ms 632 KB Output is correct
29 Correct 7 ms 504 KB Output is correct
30 Correct 7 ms 504 KB Output is correct
31 Correct 7 ms 632 KB Output is correct
32 Correct 7 ms 504 KB Output is correct
33 Correct 7 ms 508 KB Output is correct
34 Correct 7 ms 632 KB Output is correct
35 Correct 7 ms 504 KB Output is correct
36 Correct 7 ms 508 KB Output is correct
37 Correct 7 ms 632 KB Output is correct
38 Correct 7 ms 504 KB Output is correct
39 Correct 7 ms 504 KB Output is correct
40 Correct 7 ms 504 KB Output is correct
41 Correct 7 ms 632 KB Output is correct
42 Correct 7 ms 504 KB Output is correct
43 Correct 7 ms 504 KB Output is correct
44 Correct 7 ms 632 KB Output is correct
45 Correct 7 ms 504 KB Output is correct
46 Correct 7 ms 504 KB Output is correct
47 Correct 7 ms 632 KB Output is correct
48 Correct 7 ms 504 KB Output is correct
49 Correct 7 ms 504 KB Output is correct
50 Correct 7 ms 504 KB Output is correct
51 Correct 7 ms 504 KB Output is correct
52 Correct 240 ms 24660 KB Output is correct
53 Correct 239 ms 24696 KB Output is correct
54 Correct 239 ms 24828 KB Output is correct
55 Correct 238 ms 24700 KB Output is correct
56 Correct 240 ms 24772 KB Output is correct
57 Correct 239 ms 24696 KB Output is correct
58 Correct 239 ms 24696 KB Output is correct
59 Correct 239 ms 24712 KB Output is correct
60 Correct 241 ms 24696 KB Output is correct
61 Correct 238 ms 24696 KB Output is correct
62 Correct 239 ms 24820 KB Output is correct
63 Correct 243 ms 24728 KB Output is correct
64 Correct 231 ms 24696 KB Output is correct
65 Correct 238 ms 24696 KB Output is correct
66 Correct 237 ms 24696 KB Output is correct
67 Correct 242 ms 24824 KB Output is correct
68 Correct 242 ms 24924 KB Output is correct