Submission #886427

# Submission time Handle Problem Language Result Execution time Memory
886427 2023-12-12T06:44:01 Z tsumondai Rainy Markets (CCO22_day1problem2) C++14
25 / 25
516 ms 152496 KB
#include <bits/stdc++.h>
using namespace std;

#define Task "problemname"
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int MAXN = 1e6 + 5;

const int oo = 1e18, mod = 1e9 + 7;

int N;
int A[MAXN + 10], B[MAXN + 10], P[MAXN + 10], PP[MAXN + 10];
ii ans[MAXN + 10];
int ans2[MAXN + 10];

struct BIT {
	int tree[MAXN + 10];
	void update(int i, int k) { for (; i <= N; i += (i & -i)) tree[i] += k; }
	int query(int i) { int ret = 0; for (; i > 0; i -= (i & -i)) ret += tree[i]; return ret; }
} bit;

void process() {
	cin >> N;
	foru(i,1,N) cin >> A[i];
	foru(i,1,N-1) cin >> P[i], PP[i] = P[i];
	foru(i,1,N-1) cin >> B[i];

	foru(i,1,N-1) {
		int t = min(P[i], A[i]);
		P[i] -= t; A[i] -= t; ans[i].first = t;
		t = min(P[i], A[i + 1]);
		P[i] -= t; A[i + 1] -= t; ans[i].second = t;
	}

	vector<ii> VL, VR;
	for (int i = N - 1; i >= 2; i--) VR.push_back({ans[i].first, i});
	foru(i,1,N-1) {
		int t = min(P[i], B[i]);
		P[i] -= t; B[i] -= t;

		while (!VL.empty() && P[i]) {
			t = min({P[i], VL.back().first, B[VL.back().second]});
			P[i] -= t; VL.back().first -= t; B[VL.back().second] -= t;
			bit.update(i, t); bit.update(VL.back().second, -t);

			if (VL.back().first == 0) VL.clear();
			else if (B[VL.back().second] == 0) {
				ii tt = VL.back(); VL.pop_back();
				if (!VL.empty()) VL.back().first = min(VL.back().first, tt.first);
			}
		}

		while (!VR.empty() && VR.back().second <= i) VR.pop_back();
		while (!VR.empty() && P[i]) {
			t = min({P[i], VR.back().first, B[VR.back().second]});
			P[i] -= t; VR.back().first -= t; B[VR.back().second] -= t;
			bit.update(i, t); bit.update(VR.back().second, -t);

			if (VR.back().first == 0) break;
			else if (B[VR.back().second] == 0) {
				ii tt = VR.back(); VR.pop_back();
				if (!VR.empty()) VR.back().first = min(VR.back().first, tt.first);
			}
		}

		if (P[i]) {
			cout << "NO\n"; return;
		}

		VL.push_back({bit.query(i) + ans[i].second, i});
	}
	foru(i,1,N-1) {
		int t = bit.query(i);
		ans[i].second += t, ans[i + 1].first -= t;
	}

	int sum = 0;
	foru(i,1,N-1) {
		ans2[i] = PP[i] - ans[i].first - ans[i].second;
		sum += ans2[i];
	}
	cout << "YES\n" << sum << '\n';
	foru(i, 1, N - 1) cout << ans[i].fi << ' ' << ans2[i] << ' ' << ans[i].se << '\n';
	cout << '\n';
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	if (fopen(Task".INP", "r")) {
		freopen(Task".INP", "r", stdin);
		freopen(Task".OUT", "w", stdout);
	}
	process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

// dont stop

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:101:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |   freopen(Task".INP", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:102:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |   freopen(Task".OUT", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 12636 KB Output is correct
3 Correct 1 ms 12888 KB Output is correct
4 Correct 176 ms 84708 KB Output is correct
5 Correct 206 ms 90052 KB Output is correct
6 Correct 209 ms 105764 KB Output is correct
7 Correct 232 ms 112060 KB Output is correct
8 Correct 3 ms 15136 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 294 ms 99104 KB Output is correct
11 Correct 322 ms 102332 KB Output is correct
12 Correct 403 ms 127936 KB Output is correct
13 Correct 391 ms 123240 KB Output is correct
14 Correct 179 ms 83268 KB Output is correct
15 Correct 431 ms 130084 KB Output is correct
16 Correct 409 ms 131360 KB Output is correct
17 Correct 419 ms 130532 KB Output is correct
18 Correct 401 ms 130592 KB Output is correct
19 Correct 430 ms 129828 KB Output is correct
20 Correct 420 ms 131364 KB Output is correct
21 Correct 414 ms 129948 KB Output is correct
22 Correct 407 ms 127268 KB Output is correct
23 Correct 415 ms 129992 KB Output is correct
24 Correct 416 ms 128740 KB Output is correct
25 Correct 209 ms 89908 KB Output is correct
26 Correct 208 ms 90032 KB Output is correct
27 Correct 407 ms 131632 KB Output is correct
28 Correct 409 ms 128092 KB Output is correct
29 Correct 403 ms 130340 KB Output is correct
30 Correct 403 ms 130212 KB Output is correct
31 Correct 410 ms 128656 KB Output is correct
32 Correct 400 ms 130444 KB Output is correct
33 Correct 203 ms 90048 KB Output is correct
34 Correct 209 ms 89280 KB Output is correct
35 Correct 210 ms 89944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12752 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12776 KB Output is correct
11 Correct 2 ms 12888 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12888 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 3 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 2 ms 12888 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 2 ms 12892 KB Output is correct
29 Correct 2 ms 12888 KB Output is correct
30 Correct 2 ms 12892 KB Output is correct
31 Correct 2 ms 12796 KB Output is correct
32 Correct 2 ms 12892 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 1 ms 10724 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12752 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12776 KB Output is correct
11 Correct 2 ms 12888 KB Output is correct
12 Correct 2 ms 12888 KB Output is correct
13 Correct 2 ms 12888 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 3 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 2 ms 12888 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 2 ms 12892 KB Output is correct
29 Correct 2 ms 12888 KB Output is correct
30 Correct 2 ms 12892 KB Output is correct
31 Correct 2 ms 12796 KB Output is correct
32 Correct 2 ms 12892 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 1 ms 10724 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 3 ms 14940 KB Output is correct
39 Correct 2 ms 12892 KB Output is correct
40 Correct 2 ms 12888 KB Output is correct
41 Correct 2 ms 12888 KB Output is correct
42 Correct 2 ms 12632 KB Output is correct
43 Correct 1 ms 12636 KB Output is correct
44 Correct 2 ms 12800 KB Output is correct
45 Correct 2 ms 12892 KB Output is correct
46 Correct 2 ms 12952 KB Output is correct
47 Correct 2 ms 12892 KB Output is correct
48 Correct 4 ms 14940 KB Output is correct
49 Correct 3 ms 14936 KB Output is correct
50 Correct 3 ms 14936 KB Output is correct
51 Correct 3 ms 15092 KB Output is correct
52 Correct 3 ms 14940 KB Output is correct
53 Correct 2 ms 12892 KB Output is correct
54 Correct 3 ms 14940 KB Output is correct
55 Correct 4 ms 15108 KB Output is correct
56 Correct 4 ms 14936 KB Output is correct
57 Correct 3 ms 14940 KB Output is correct
58 Correct 3 ms 14936 KB Output is correct
59 Correct 3 ms 14940 KB Output is correct
60 Correct 3 ms 14940 KB Output is correct
61 Correct 4 ms 15184 KB Output is correct
62 Correct 3 ms 14940 KB Output is correct
63 Correct 3 ms 14940 KB Output is correct
64 Correct 2 ms 12892 KB Output is correct
65 Correct 2 ms 12892 KB Output is correct
66 Correct 3 ms 15064 KB Output is correct
67 Correct 3 ms 14940 KB Output is correct
68 Correct 4 ms 14940 KB Output is correct
69 Correct 4 ms 15064 KB Output is correct
70 Correct 3 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 12636 KB Output is correct
3 Correct 1 ms 12888 KB Output is correct
4 Correct 176 ms 84708 KB Output is correct
5 Correct 206 ms 90052 KB Output is correct
6 Correct 209 ms 105764 KB Output is correct
7 Correct 232 ms 112060 KB Output is correct
8 Correct 3 ms 15136 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 294 ms 99104 KB Output is correct
11 Correct 322 ms 102332 KB Output is correct
12 Correct 403 ms 127936 KB Output is correct
13 Correct 391 ms 123240 KB Output is correct
14 Correct 179 ms 83268 KB Output is correct
15 Correct 431 ms 130084 KB Output is correct
16 Correct 409 ms 131360 KB Output is correct
17 Correct 419 ms 130532 KB Output is correct
18 Correct 401 ms 130592 KB Output is correct
19 Correct 430 ms 129828 KB Output is correct
20 Correct 420 ms 131364 KB Output is correct
21 Correct 414 ms 129948 KB Output is correct
22 Correct 407 ms 127268 KB Output is correct
23 Correct 415 ms 129992 KB Output is correct
24 Correct 416 ms 128740 KB Output is correct
25 Correct 209 ms 89908 KB Output is correct
26 Correct 208 ms 90032 KB Output is correct
27 Correct 407 ms 131632 KB Output is correct
28 Correct 409 ms 128092 KB Output is correct
29 Correct 403 ms 130340 KB Output is correct
30 Correct 403 ms 130212 KB Output is correct
31 Correct 410 ms 128656 KB Output is correct
32 Correct 400 ms 130444 KB Output is correct
33 Correct 203 ms 90048 KB Output is correct
34 Correct 209 ms 89280 KB Output is correct
35 Correct 210 ms 89944 KB Output is correct
36 Correct 2 ms 12752 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
39 Correct 1 ms 12636 KB Output is correct
40 Correct 2 ms 10584 KB Output is correct
41 Correct 2 ms 10584 KB Output is correct
42 Correct 2 ms 10584 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 12892 KB Output is correct
45 Correct 2 ms 12776 KB Output is correct
46 Correct 2 ms 12888 KB Output is correct
47 Correct 2 ms 12888 KB Output is correct
48 Correct 2 ms 12888 KB Output is correct
49 Correct 2 ms 10588 KB Output is correct
50 Correct 2 ms 12892 KB Output is correct
51 Correct 2 ms 12892 KB Output is correct
52 Correct 2 ms 12892 KB Output is correct
53 Correct 3 ms 12888 KB Output is correct
54 Correct 2 ms 12892 KB Output is correct
55 Correct 2 ms 12892 KB Output is correct
56 Correct 3 ms 12892 KB Output is correct
57 Correct 2 ms 12892 KB Output is correct
58 Correct 3 ms 12892 KB Output is correct
59 Correct 2 ms 12888 KB Output is correct
60 Correct 2 ms 10588 KB Output is correct
61 Correct 2 ms 10588 KB Output is correct
62 Correct 2 ms 12892 KB Output is correct
63 Correct 2 ms 12892 KB Output is correct
64 Correct 2 ms 12888 KB Output is correct
65 Correct 2 ms 12892 KB Output is correct
66 Correct 2 ms 12796 KB Output is correct
67 Correct 2 ms 12892 KB Output is correct
68 Correct 2 ms 10588 KB Output is correct
69 Correct 2 ms 10588 KB Output is correct
70 Correct 2 ms 10588 KB Output is correct
71 Correct 1 ms 10724 KB Output is correct
72 Correct 2 ms 12636 KB Output is correct
73 Correct 3 ms 14940 KB Output is correct
74 Correct 2 ms 12892 KB Output is correct
75 Correct 2 ms 12888 KB Output is correct
76 Correct 2 ms 12888 KB Output is correct
77 Correct 2 ms 12632 KB Output is correct
78 Correct 1 ms 12636 KB Output is correct
79 Correct 2 ms 12800 KB Output is correct
80 Correct 2 ms 12892 KB Output is correct
81 Correct 2 ms 12952 KB Output is correct
82 Correct 2 ms 12892 KB Output is correct
83 Correct 4 ms 14940 KB Output is correct
84 Correct 3 ms 14936 KB Output is correct
85 Correct 3 ms 14936 KB Output is correct
86 Correct 3 ms 15092 KB Output is correct
87 Correct 3 ms 14940 KB Output is correct
88 Correct 2 ms 12892 KB Output is correct
89 Correct 3 ms 14940 KB Output is correct
90 Correct 4 ms 15108 KB Output is correct
91 Correct 4 ms 14936 KB Output is correct
92 Correct 3 ms 14940 KB Output is correct
93 Correct 3 ms 14936 KB Output is correct
94 Correct 3 ms 14940 KB Output is correct
95 Correct 3 ms 14940 KB Output is correct
96 Correct 4 ms 15184 KB Output is correct
97 Correct 3 ms 14940 KB Output is correct
98 Correct 3 ms 14940 KB Output is correct
99 Correct 2 ms 12892 KB Output is correct
100 Correct 2 ms 12892 KB Output is correct
101 Correct 3 ms 15064 KB Output is correct
102 Correct 3 ms 14940 KB Output is correct
103 Correct 4 ms 14940 KB Output is correct
104 Correct 4 ms 15064 KB Output is correct
105 Correct 3 ms 14940 KB Output is correct
106 Correct 2 ms 12632 KB Output is correct
107 Correct 1 ms 12636 KB Output is correct
108 Correct 471 ms 110376 KB Output is correct
109 Correct 499 ms 119196 KB Output is correct
110 Correct 368 ms 117972 KB Output is correct
111 Correct 385 ms 127244 KB Output is correct
112 Correct 4 ms 15196 KB Output is correct
113 Correct 4 ms 15204 KB Output is correct
114 Correct 502 ms 137112 KB Output is correct
115 Correct 467 ms 146976 KB Output is correct
116 Correct 385 ms 91316 KB Output is correct
117 Correct 347 ms 111644 KB Output is correct
118 Correct 417 ms 131876 KB Output is correct
119 Correct 173 ms 82880 KB Output is correct
120 Correct 500 ms 137228 KB Output is correct
121 Correct 516 ms 137104 KB Output is correct
122 Correct 491 ms 137268 KB Output is correct
123 Correct 508 ms 137768 KB Output is correct
124 Correct 492 ms 137732 KB Output is correct
125 Correct 488 ms 138560 KB Output is correct
126 Correct 497 ms 143756 KB Output is correct
127 Correct 447 ms 146468 KB Output is correct
128 Correct 495 ms 137136 KB Output is correct
129 Correct 488 ms 152496 KB Output is correct
130 Correct 243 ms 97480 KB Output is correct
131 Correct 246 ms 97372 KB Output is correct
132 Correct 494 ms 136688 KB Output is correct
133 Correct 246 ms 99820 KB Output is correct
134 Correct 502 ms 137124 KB Output is correct
135 Correct 498 ms 137028 KB Output is correct
136 Correct 481 ms 143572 KB Output is correct
137 Correct 486 ms 137652 KB Output is correct
138 Correct 244 ms 97468 KB Output is correct
139 Correct 245 ms 97728 KB Output is correct
140 Correct 241 ms 96548 KB Output is correct