답안 #710980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710980 2023-03-16T06:31:42 Z pavement Rainy Markets (CCO22_day1problem2) C++17
25 / 25
675 ms 141516 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, ans, srb, diff[1000005], B[1000005], P[1000005], U[1000005], V[1000005], ml[1000005], mr[1000005], OP[1000005];
vector<iii> rb;

int fill(int &a, int &b) {
	int c = min(a, b);
	a -= c;
	b -= c;
	return c;
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> B[i];
	}
	for (int i = 1; i < N; i++) {
		cin >> P[i];
		OP[i] = P[i];
	}
	for (int i = 1; i < N; i++) {
		cin >> U[i];
		int tmp = P[i];
		P[i] = max(0ll, P[i] - U[i]);
		V[i] = tmp - P[i];
		assert(P[i] + V[i] == OP[i]);
	}
	for (int i = 1; i < N; i++) {
		ml[i] += fill(B[i], P[i]);
		mr[i] += fill(B[i + 1], P[i]);
		if (P[i]) {
			if (srb < P[i]) return cout << "NO\n", 0;
			int cnt = 0;
			while (cnt < P[i]) {
				assert(!rb.empty());
				auto [v, idx, dir] = rb.back();
				//~ cout << "RB " << v << ' ' << idx << ' ' << dir << '\n';
				if (cnt + v > P[i]) {
					if (dir) mr[idx] -= P[i] - cnt;
					else ml[idx] -= P[i] - cnt;
					V[idx] += P[i] - cnt;
					B[i] += P[i] - cnt;
					g0(rb.back()) -= P[i] - cnt;
					srb -= P[i] - cnt;
					diff[idx + dir] += P[i] - cnt;
					diff[i] -= P[i] - cnt;
					cnt = P[i];
				} else {
					if (dir) mr[idx] -= v;
					else ml[idx] -= v;
					V[idx] += v;
					B[i] += v;
					cnt += v;
					srb -= v;
					diff[idx + dir] += v;
					diff[i] -= v;
					rb.ppb();
				}
			}
			//~ cout << "NOW " << B[i] << ' ' << B[i + 1] << ' ' << P[i] << '\n';
			ml[i] += fill(B[i], P[i]);
			mr[i] += fill(B[i + 1], P[i]);
			//~ cout << "RES " << P[i] << '\n';
		}
		//~ cout << "HERE " << i << ' ' << B[i] << ' ' << B[i + 1] << ' ' << V[i] << '\n';
		int tmp1 = fill(B[i], V[i]);
		int tmp2 = fill(B[i + 1], V[i]);
		ml[i] += tmp1;
		mr[i] += tmp2;
		srb += tmp1 + tmp2;
		//~ cout << "T12 " << tmp1 << ' ' << tmp2 << '\n';
		rb.eb(tmp1, i, 0);
		rb.eb(tmp2, i, 1);
		while (srb > mr[i]) {
			if (g0(rb.back()) <= srb - mr[i]) {
				srb -= g0(rb.back());
				rb.ppb();
			} else {
				g0(rb.back()) -= (srb - mr[i]);
				srb = mr[i];
			}
		}
		//~ cout << "! " << i << ' ' << ml[i] << ' ' << mr[i] << '\n';
	}
	for (int i = 1; i < N; i++) {
		ans += V[i];
	}
	cout << "YES\n" << ans << '\n';
	for (int i = 1; i < N; i++) {
		diff[i] += diff[i - 1];
		assert(ml[i] + V[i] + mr[i] == OP[i]);
		cout << ml[i] + diff[i] << ' ' << V[i] << ' ' << mr[i] - diff[i] << '\n';
		assert(ml[i] + diff[i] >= 0 && V[i] >= 0 && mr[i] - diff[i] >= 0);
	}
}

Compilation message

Main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 204 ms 39468 KB Output is correct
5 Correct 242 ms 39364 KB Output is correct
6 Correct 349 ms 102184 KB Output is correct
7 Correct 311 ms 102208 KB Output is correct
8 Correct 3 ms 1044 KB Output is correct
9 Correct 3 ms 1044 KB Output is correct
10 Correct 389 ms 116068 KB Output is correct
11 Correct 394 ms 117644 KB Output is correct
12 Correct 530 ms 129744 KB Output is correct
13 Correct 529 ms 124036 KB Output is correct
14 Correct 239 ms 39456 KB Output is correct
15 Correct 592 ms 131600 KB Output is correct
16 Correct 580 ms 131740 KB Output is correct
17 Correct 599 ms 131624 KB Output is correct
18 Correct 480 ms 131660 KB Output is correct
19 Correct 508 ms 131596 KB Output is correct
20 Correct 479 ms 131608 KB Output is correct
21 Correct 511 ms 131456 KB Output is correct
22 Correct 496 ms 129004 KB Output is correct
23 Correct 483 ms 131660 KB Output is correct
24 Correct 476 ms 130832 KB Output is correct
25 Correct 230 ms 43216 KB Output is correct
26 Correct 228 ms 39508 KB Output is correct
27 Correct 489 ms 131620 KB Output is correct
28 Correct 548 ms 129700 KB Output is correct
29 Correct 513 ms 131740 KB Output is correct
30 Correct 523 ms 131640 KB Output is correct
31 Correct 495 ms 130484 KB Output is correct
32 Correct 487 ms 131644 KB Output is correct
33 Correct 228 ms 39464 KB Output is correct
34 Correct 228 ms 41412 KB Output is correct
35 Correct 228 ms 39372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 528 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 528 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 596 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 2 ms 596 KB Output is correct
55 Correct 2 ms 660 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 2 ms 596 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 2 ms 596 KB Output is correct
62 Correct 2 ms 596 KB Output is correct
63 Correct 2 ms 596 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 2 ms 596 KB Output is correct
67 Correct 2 ms 596 KB Output is correct
68 Correct 2 ms 596 KB Output is correct
69 Correct 2 ms 596 KB Output is correct
70 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 204 ms 39468 KB Output is correct
5 Correct 242 ms 39364 KB Output is correct
6 Correct 349 ms 102184 KB Output is correct
7 Correct 311 ms 102208 KB Output is correct
8 Correct 3 ms 1044 KB Output is correct
9 Correct 3 ms 1044 KB Output is correct
10 Correct 389 ms 116068 KB Output is correct
11 Correct 394 ms 117644 KB Output is correct
12 Correct 530 ms 129744 KB Output is correct
13 Correct 529 ms 124036 KB Output is correct
14 Correct 239 ms 39456 KB Output is correct
15 Correct 592 ms 131600 KB Output is correct
16 Correct 580 ms 131740 KB Output is correct
17 Correct 599 ms 131624 KB Output is correct
18 Correct 480 ms 131660 KB Output is correct
19 Correct 508 ms 131596 KB Output is correct
20 Correct 479 ms 131608 KB Output is correct
21 Correct 511 ms 131456 KB Output is correct
22 Correct 496 ms 129004 KB Output is correct
23 Correct 483 ms 131660 KB Output is correct
24 Correct 476 ms 130832 KB Output is correct
25 Correct 230 ms 43216 KB Output is correct
26 Correct 228 ms 39508 KB Output is correct
27 Correct 489 ms 131620 KB Output is correct
28 Correct 548 ms 129700 KB Output is correct
29 Correct 513 ms 131740 KB Output is correct
30 Correct 523 ms 131640 KB Output is correct
31 Correct 495 ms 130484 KB Output is correct
32 Correct 487 ms 131644 KB Output is correct
33 Correct 228 ms 39464 KB Output is correct
34 Correct 228 ms 41412 KB Output is correct
35 Correct 228 ms 39372 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 528 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 2 ms 596 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 0 ms 340 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 1 ms 596 KB Output is correct
82 Correct 1 ms 596 KB Output is correct
83 Correct 2 ms 596 KB Output is correct
84 Correct 2 ms 596 KB Output is correct
85 Correct 2 ms 596 KB Output is correct
86 Correct 2 ms 596 KB Output is correct
87 Correct 2 ms 596 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 2 ms 596 KB Output is correct
90 Correct 2 ms 660 KB Output is correct
91 Correct 2 ms 596 KB Output is correct
92 Correct 2 ms 596 KB Output is correct
93 Correct 2 ms 596 KB Output is correct
94 Correct 2 ms 596 KB Output is correct
95 Correct 3 ms 596 KB Output is correct
96 Correct 2 ms 596 KB Output is correct
97 Correct 2 ms 596 KB Output is correct
98 Correct 2 ms 596 KB Output is correct
99 Correct 1 ms 468 KB Output is correct
100 Correct 1 ms 468 KB Output is correct
101 Correct 2 ms 596 KB Output is correct
102 Correct 2 ms 596 KB Output is correct
103 Correct 2 ms 596 KB Output is correct
104 Correct 2 ms 596 KB Output is correct
105 Correct 2 ms 592 KB Output is correct
106 Correct 1 ms 340 KB Output is correct
107 Correct 0 ms 340 KB Output is correct
108 Correct 411 ms 78792 KB Output is correct
109 Correct 496 ms 84856 KB Output is correct
110 Correct 474 ms 141516 KB Output is correct
111 Correct 487 ms 133504 KB Output is correct
112 Correct 3 ms 852 KB Output is correct
113 Correct 3 ms 852 KB Output is correct
114 Correct 561 ms 95928 KB Output is correct
115 Correct 555 ms 94540 KB Output is correct
116 Correct 371 ms 75852 KB Output is correct
117 Correct 375 ms 79808 KB Output is correct
118 Correct 550 ms 80792 KB Output is correct
119 Correct 198 ms 53444 KB Output is correct
120 Correct 565 ms 95844 KB Output is correct
121 Correct 585 ms 95780 KB Output is correct
122 Correct 607 ms 95696 KB Output is correct
123 Correct 578 ms 97052 KB Output is correct
124 Correct 675 ms 96908 KB Output is correct
125 Correct 582 ms 95436 KB Output is correct
126 Correct 620 ms 95416 KB Output is correct
127 Correct 630 ms 92528 KB Output is correct
128 Correct 633 ms 95516 KB Output is correct
129 Correct 632 ms 95388 KB Output is correct
130 Correct 345 ms 43520 KB Output is correct
131 Correct 327 ms 42952 KB Output is correct
132 Correct 612 ms 95352 KB Output is correct
133 Correct 335 ms 44316 KB Output is correct
134 Correct 586 ms 121148 KB Output is correct
135 Correct 587 ms 121120 KB Output is correct
136 Correct 604 ms 120924 KB Output is correct
137 Correct 621 ms 121160 KB Output is correct
138 Correct 336 ms 68700 KB Output is correct
139 Correct 377 ms 68808 KB Output is correct
140 Correct 354 ms 67760 KB Output is correct