답안 #1065500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065500 2024-08-19T08:37:08 Z Tob Arranging Tickets (JOI17_arranging_tickets) C++14
100 / 100
1522 ms 20920 KB
#include <bits/stdc++.h>

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const int N = 2e5 + 7;

int n, m;
ll a[N], l[N], r[N], c[N], ps[N];
vector <pii> iv[N];
map <ll, ll> s;

bool check(int t, ll b, ll d) {
	if (d > b || d < 0) return 0;
	s.clear();
	for (int i = 0; i <= n; i++) ps[i] = 0;
	ll cnt = 0;
	for (int i = 1; i <= t; i++) {
		ll ne = (a[i]-b+d+1)/2;
		for (auto it : iv[i]) if (it.F >= t) s[it.F] += it.S;
		while (cnt < ne) {
			if (s.empty()) return 0;
			auto p = --s.end();
			ll dod = ne-cnt;
			if (p->S <= ne-cnt) {
				dod = p->S;
				s.erase(p);
			}
			else s[p->F] -= dod;
			cnt += dod;
			ps[0] += dod;
			ps[i] -= 2*dod;
			ps[p->F+1] += 2*dod;
		}
	}
	for (int i = 0; i < n; i++) {
		if (i) ps[i] += ps[i-1];
		if (a[i] + ps[i] > b) return 0;
	}
	return 1;
}

int main () {
	FIO;
	cin >> n >> m;
	
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> c[i];
		if (l[i] > r[i]) swap(l[i], r[i]);
		r[i]--;
		a[l[i]] += c[i];
		a[r[i]+1] -= c[i];
		iv[l[i]].pb({r[i], c[i]});
	}
	for (int i = 1; i < n; i++) a[i] += a[i-1];
	int p = 1;
	for (int i = 2; i < n; i++) if (a[i] > a[p]) p = i;
	
	ll lo = 0, hi = a[p];
	while (lo < hi) {
		ll mid = (lo + hi) / 2;
		int o = 0;
		o |= check(p, mid, a[p]-mid) | check(p, mid, a[p]-mid+1);
		if (o) hi = mid;
		else lo = mid+1;
	}
	cout << lo << "\n";

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12904 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12936 KB Output is correct
5 Correct 1 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12904 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12936 KB Output is correct
5 Correct 1 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12696 KB Output is correct
16 Correct 2 ms 12888 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 2 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 2 ms 12892 KB Output is correct
24 Correct 2 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12904 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12936 KB Output is correct
5 Correct 1 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12696 KB Output is correct
16 Correct 2 ms 12888 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 2 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 2 ms 12892 KB Output is correct
24 Correct 2 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 7 ms 12968 KB Output is correct
29 Correct 6 ms 12892 KB Output is correct
30 Correct 7 ms 12892 KB Output is correct
31 Correct 6 ms 12892 KB Output is correct
32 Correct 8 ms 12888 KB Output is correct
33 Correct 7 ms 13092 KB Output is correct
34 Correct 3 ms 12888 KB Output is correct
35 Correct 7 ms 13096 KB Output is correct
36 Correct 7 ms 13080 KB Output is correct
37 Correct 3 ms 12892 KB Output is correct
38 Correct 3 ms 12892 KB Output is correct
39 Correct 2 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12904 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12936 KB Output is correct
5 Correct 1 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12696 KB Output is correct
16 Correct 2 ms 12888 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 2 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 2 ms 12892 KB Output is correct
24 Correct 2 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 7 ms 12968 KB Output is correct
29 Correct 6 ms 12892 KB Output is correct
30 Correct 7 ms 12892 KB Output is correct
31 Correct 6 ms 12892 KB Output is correct
32 Correct 8 ms 12888 KB Output is correct
33 Correct 7 ms 13092 KB Output is correct
34 Correct 3 ms 12888 KB Output is correct
35 Correct 7 ms 13096 KB Output is correct
36 Correct 7 ms 13080 KB Output is correct
37 Correct 3 ms 12892 KB Output is correct
38 Correct 3 ms 12892 KB Output is correct
39 Correct 2 ms 12892 KB Output is correct
40 Correct 495 ms 18220 KB Output is correct
41 Correct 519 ms 18176 KB Output is correct
42 Correct 491 ms 18516 KB Output is correct
43 Correct 403 ms 17484 KB Output is correct
44 Correct 274 ms 17264 KB Output is correct
45 Correct 425 ms 17500 KB Output is correct
46 Correct 493 ms 18012 KB Output is correct
47 Correct 34 ms 16980 KB Output is correct
48 Correct 32 ms 17240 KB Output is correct
49 Correct 31 ms 17748 KB Output is correct
50 Correct 21 ms 16220 KB Output is correct
51 Correct 31 ms 17236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12904 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12936 KB Output is correct
5 Correct 1 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12696 KB Output is correct
16 Correct 2 ms 12888 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 2 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 2 ms 12892 KB Output is correct
24 Correct 2 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 7 ms 12968 KB Output is correct
29 Correct 6 ms 12892 KB Output is correct
30 Correct 7 ms 12892 KB Output is correct
31 Correct 6 ms 12892 KB Output is correct
32 Correct 8 ms 12888 KB Output is correct
33 Correct 7 ms 13092 KB Output is correct
34 Correct 3 ms 12888 KB Output is correct
35 Correct 7 ms 13096 KB Output is correct
36 Correct 7 ms 13080 KB Output is correct
37 Correct 3 ms 12892 KB Output is correct
38 Correct 3 ms 12892 KB Output is correct
39 Correct 2 ms 12892 KB Output is correct
40 Correct 495 ms 18220 KB Output is correct
41 Correct 519 ms 18176 KB Output is correct
42 Correct 491 ms 18516 KB Output is correct
43 Correct 403 ms 17484 KB Output is correct
44 Correct 274 ms 17264 KB Output is correct
45 Correct 425 ms 17500 KB Output is correct
46 Correct 493 ms 18012 KB Output is correct
47 Correct 34 ms 16980 KB Output is correct
48 Correct 32 ms 17240 KB Output is correct
49 Correct 31 ms 17748 KB Output is correct
50 Correct 21 ms 16220 KB Output is correct
51 Correct 31 ms 17236 KB Output is correct
52 Correct 937 ms 18000 KB Output is correct
53 Correct 1522 ms 20920 KB Output is correct
54 Correct 1422 ms 20564 KB Output is correct
55 Correct 666 ms 19428 KB Output is correct
56 Correct 1279 ms 19536 KB Output is correct
57 Correct 1321 ms 19984 KB Output is correct
58 Correct 996 ms 19616 KB Output is correct
59 Correct 36 ms 20564 KB Output is correct