Submission #710923

# Submission time Handle Problem Language Result Execution time Memory
710923 2023-03-16T05:24:56 Z pavement Rainy Markets (CCO22_day1problem2) C++17
16 / 25
727 ms 150428 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, upds;

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]);
		//~ cout << "@ " << i << ' ' << ml[i] << ' ' << mr[i] << '\n';
		if (P[i]) {
			if (srb < P[i]) return cout << "NO\n", 0;
			int cnt = 0;
			while (cnt < P[i]) {
				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 + 1] += 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 + 1] += 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';
		}
		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);
		if (mr[i] == 0) {
			rb.clear();
			srb = 0;
		}
		//~ 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';
	}
}

Compilation message

Main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 200 ms 39484 KB Output is correct
5 Correct 232 ms 39404 KB Output is correct
6 Correct 268 ms 102156 KB Output is correct
7 Correct 285 ms 102276 KB Output is correct
8 Correct 3 ms 1044 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 334 ms 68972 KB Output is correct
11 Correct 385 ms 70504 KB Output is correct
12 Correct 478 ms 82632 KB Output is correct
13 Correct 487 ms 76984 KB Output is correct
14 Correct 188 ms 39432 KB Output is correct
15 Correct 465 ms 86052 KB Output is correct
16 Correct 455 ms 85392 KB Output is correct
17 Correct 459 ms 85368 KB Output is correct
18 Correct 460 ms 84880 KB Output is correct
19 Correct 474 ms 84796 KB Output is correct
20 Correct 447 ms 84528 KB Output is correct
21 Correct 531 ms 84424 KB Output is correct
22 Correct 534 ms 81860 KB Output is correct
23 Correct 727 ms 88576 KB Output is correct
24 Correct 498 ms 83792 KB Output is correct
25 Correct 257 ms 43160 KB Output is correct
26 Correct 274 ms 39368 KB Output is correct
27 Correct 622 ms 86548 KB Output is correct
28 Correct 489 ms 82600 KB Output is correct
29 Correct 491 ms 131812 KB Output is correct
30 Correct 488 ms 86988 KB Output is correct
31 Correct 468 ms 83432 KB Output is correct
32 Correct 448 ms 86548 KB Output is correct
33 Correct 239 ms 39416 KB Output is correct
34 Correct 236 ms 41560 KB Output is correct
35 Correct 241 ms 39472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 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 2 ms 604 KB Output is correct
10 Correct 1 ms 484 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 1 ms 484 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 524 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 520 KB Output is correct
19 Correct 1 ms 480 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 404 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 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 2 ms 604 KB Output is correct
10 Correct 1 ms 484 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 1 ms 484 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 524 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 520 KB Output is correct
19 Correct 1 ms 480 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 404 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 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 792 KB Output is correct
39 Correct 1 ms 484 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 2 ms 596 KB Output is correct
48 Correct 3 ms 740 KB Output is correct
49 Correct 3 ms 672 KB Output is correct
50 Correct 2 ms 608 KB Output is correct
51 Correct 2 ms 916 KB Output is correct
52 Correct 2 ms 672 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 2 ms 852 KB Output is correct
55 Correct 3 ms 988 KB Output is correct
56 Correct 4 ms 976 KB Output is correct
57 Correct 2 ms 716 KB Output is correct
58 Correct 2 ms 736 KB Output is correct
59 Correct 2 ms 724 KB Output is correct
60 Correct 3 ms 724 KB Output is correct
61 Correct 4 ms 724 KB Output is correct
62 Correct 3 ms 724 KB Output is correct
63 Correct 2 ms 740 KB Output is correct
64 Correct 1 ms 596 KB Output is correct
65 Correct 1 ms 484 KB Output is correct
66 Correct 3 ms 724 KB Output is correct
67 Correct 2 ms 724 KB Output is correct
68 Correct 3 ms 724 KB Output is correct
69 Correct 4 ms 724 KB Output is correct
70 Correct 2 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 200 ms 39484 KB Output is correct
5 Correct 232 ms 39404 KB Output is correct
6 Correct 268 ms 102156 KB Output is correct
7 Correct 285 ms 102276 KB Output is correct
8 Correct 3 ms 1044 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 334 ms 68972 KB Output is correct
11 Correct 385 ms 70504 KB Output is correct
12 Correct 478 ms 82632 KB Output is correct
13 Correct 487 ms 76984 KB Output is correct
14 Correct 188 ms 39432 KB Output is correct
15 Correct 465 ms 86052 KB Output is correct
16 Correct 455 ms 85392 KB Output is correct
17 Correct 459 ms 85368 KB Output is correct
18 Correct 460 ms 84880 KB Output is correct
19 Correct 474 ms 84796 KB Output is correct
20 Correct 447 ms 84528 KB Output is correct
21 Correct 531 ms 84424 KB Output is correct
22 Correct 534 ms 81860 KB Output is correct
23 Correct 727 ms 88576 KB Output is correct
24 Correct 498 ms 83792 KB Output is correct
25 Correct 257 ms 43160 KB Output is correct
26 Correct 274 ms 39368 KB Output is correct
27 Correct 622 ms 86548 KB Output is correct
28 Correct 489 ms 82600 KB Output is correct
29 Correct 491 ms 131812 KB Output is correct
30 Correct 488 ms 86988 KB Output is correct
31 Correct 468 ms 83432 KB Output is correct
32 Correct 448 ms 86548 KB Output is correct
33 Correct 239 ms 39416 KB Output is correct
34 Correct 236 ms 41560 KB Output is correct
35 Correct 241 ms 39472 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 1 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 2 ms 604 KB Output is correct
45 Correct 1 ms 484 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 680 KB Output is correct
48 Correct 1 ms 484 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 2 ms 524 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 520 KB Output is correct
54 Correct 1 ms 480 KB Output is correct
55 Correct 1 ms 476 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 2 ms 612 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 404 KB Output is correct
61 Correct 1 ms 476 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 2 ms 596 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 468 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 792 KB Output is correct
74 Correct 1 ms 484 KB Output is correct
75 Correct 2 ms 596 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 596 KB Output is correct
80 Correct 2 ms 596 KB Output is correct
81 Correct 2 ms 596 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 3 ms 740 KB Output is correct
84 Correct 3 ms 672 KB Output is correct
85 Correct 2 ms 608 KB Output is correct
86 Correct 2 ms 916 KB Output is correct
87 Correct 2 ms 672 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 2 ms 852 KB Output is correct
90 Correct 3 ms 988 KB Output is correct
91 Correct 4 ms 976 KB Output is correct
92 Correct 2 ms 716 KB Output is correct
93 Correct 2 ms 736 KB Output is correct
94 Correct 2 ms 724 KB Output is correct
95 Correct 3 ms 724 KB Output is correct
96 Correct 4 ms 724 KB Output is correct
97 Correct 3 ms 724 KB Output is correct
98 Correct 2 ms 740 KB Output is correct
99 Correct 1 ms 596 KB Output is correct
100 Correct 1 ms 484 KB Output is correct
101 Correct 3 ms 724 KB Output is correct
102 Correct 2 ms 724 KB Output is correct
103 Correct 3 ms 724 KB Output is correct
104 Correct 4 ms 724 KB Output is correct
105 Correct 2 ms 736 KB Output is correct
106 Correct 1 ms 340 KB Output is correct
107 Correct 1 ms 340 KB Output is correct
108 Correct 463 ms 94512 KB Output is correct
109 Correct 524 ms 103316 KB Output is correct
110 Correct 457 ms 141520 KB Output is correct
111 Correct 501 ms 150428 KB Output is correct
112 Correct 3 ms 864 KB Output is correct
113 Correct 3 ms 1044 KB Output is correct
114 Correct 610 ms 121320 KB Output is correct
115 Correct 552 ms 131904 KB Output is correct
116 Correct 340 ms 75248 KB Output is correct
117 Correct 396 ms 81920 KB Output is correct
118 Correct 614 ms 108356 KB Output is correct
119 Correct 200 ms 53540 KB Output is correct
120 Correct 559 ms 121368 KB Output is correct
121 Correct 606 ms 121320 KB Output is correct
122 Correct 601 ms 121308 KB Output is correct
123 Correct 573 ms 121564 KB Output is correct
124 Correct 562 ms 121564 KB Output is correct
125 Correct 567 ms 120468 KB Output is correct
126 Correct 551 ms 124568 KB Output is correct
127 Correct 569 ms 117908 KB Output is correct
128 Correct 558 ms 118716 KB Output is correct
129 Correct 573 ms 135252 KB Output is correct
130 Correct 292 ms 69068 KB Output is correct
131 Correct 292 ms 68308 KB Output is correct
132 Correct 556 ms 118100 KB Output is correct
133 Incorrect 563 ms 118820 KB Integer -2208537 violates the range [0, 657331863]
134 Halted 0 ms 0 KB -