Submission #773227

# Submission time Handle Problem Language Result Execution time Memory
773227 2023-07-04T17:08:55 Z rainboy Rainy Markets (CCO22_day1problem2) C
25 / 25
1085 ms 105556 KB
#include <stdio.h>

#define N	1000000
#define N_	(1 << 20)	/* N_ = pow2(ceil(log2(N))) */

long long min(long long a, long long b) { return a < b ? a : b; }

long long ss[N_ * 2], qq[N_ * 2]; int n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	ss[i] = ss[l] + ss[r];
	qq[i] = min(qq[l] + ss[r], qq[r]);
}

void update(int i, long long x) {
	i += n_;
	ss[i] += x, qq[i] = min(ss[i], 0);
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	static int aa[N], bb[N], cc[N], dd[N], qu[N];
	int n, cnt, i, j, a, b, d;
	long long c, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i + 1 < n; i++)
		scanf("%d", &bb[i]);
	for (i = 0; i + 1 < n; i++) {
		scanf("%d", &cc[i]);
		cc[i] = min(cc[i], bb[i]);
	}
	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	cnt = 0, ans = 0;
	for (j = 0; j + 1 < n; j++) {
		update(j, aa[j] - bb[j]);
		if (cc[j] > 0)
			qu[cnt++] = j;
		c = -min(qq[1] + aa[j + 1], 0);
		ans += c;
		while (c > 0 && cnt) {
			i = qu[cnt - 1];
			d = min(c, cc[i]);
			update(i, d);
			c -= d, bb[i] -= d, cc[i] -= d, dd[i] += d;
			if (cc[i] == 0)
				cnt--;
		}
		if (qq[1] + aa[j + 1] < 0) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	printf("%lld\n", ans);
	for (i = 0; i + 1 < n; i++) {
		a = min(bb[i], aa[i]), d = dd[i], b = bb[i] - a;
		printf("%d %d %d\n", a, d, b);
		aa[i + 1] -= b;
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:33:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", &bb[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%d", &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 196 ms 27740 KB Output is correct
5 Correct 224 ms 33564 KB Output is correct
6 Correct 318 ms 58928 KB Output is correct
7 Correct 333 ms 64808 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 564 KB Output is correct
10 Correct 434 ms 55708 KB Output is correct
11 Correct 435 ms 58960 KB Output is correct
12 Correct 498 ms 84732 KB Output is correct
13 Correct 523 ms 79848 KB Output is correct
14 Correct 210 ms 26924 KB Output is correct
15 Correct 522 ms 86760 KB Output is correct
16 Correct 501 ms 86676 KB Output is correct
17 Correct 513 ms 86692 KB Output is correct
18 Correct 509 ms 86612 KB Output is correct
19 Correct 504 ms 86664 KB Output is correct
20 Correct 518 ms 86552 KB Output is correct
21 Correct 544 ms 86376 KB Output is correct
22 Correct 514 ms 83992 KB Output is correct
23 Correct 511 ms 86636 KB Output is correct
24 Correct 511 ms 85780 KB Output is correct
25 Correct 250 ms 35148 KB Output is correct
26 Correct 235 ms 33704 KB Output is correct
27 Correct 516 ms 86656 KB Output is correct
28 Correct 528 ms 84716 KB Output is correct
29 Correct 535 ms 86756 KB Output is correct
30 Correct 503 ms 86732 KB Output is correct
31 Correct 509 ms 85592 KB Output is correct
32 Correct 509 ms 86492 KB Output is correct
33 Correct 225 ms 33692 KB Output is correct
34 Correct 229 ms 34672 KB Output is correct
35 Correct 243 ms 33616 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 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 432 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 1 ms 468 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 472 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 432 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 340 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 296 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 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 432 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 1 ms 468 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 472 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 432 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 340 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 296 KB Output is correct
38 Correct 3 ms 596 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 2 ms 488 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 292 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 436 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 3 ms 640 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 3 ms 468 KB Output is correct
51 Correct 2 ms 564 KB Output is correct
52 Correct 2 ms 596 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 2 ms 596 KB Output is correct
55 Correct 3 ms 596 KB Output is correct
56 Correct 3 ms 560 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 2 ms 596 KB Output is correct
61 Correct 3 ms 568 KB Output is correct
62 Correct 3 ms 596 KB Output is correct
63 Correct 2 ms 564 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 4 ms 596 KB Output is correct
67 Correct 2 ms 596 KB Output is correct
68 Correct 3 ms 596 KB Output is correct
69 Correct 3 ms 596 KB Output is correct
70 Correct 3 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 196 ms 27740 KB Output is correct
5 Correct 224 ms 33564 KB Output is correct
6 Correct 318 ms 58928 KB Output is correct
7 Correct 333 ms 64808 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 564 KB Output is correct
10 Correct 434 ms 55708 KB Output is correct
11 Correct 435 ms 58960 KB Output is correct
12 Correct 498 ms 84732 KB Output is correct
13 Correct 523 ms 79848 KB Output is correct
14 Correct 210 ms 26924 KB Output is correct
15 Correct 522 ms 86760 KB Output is correct
16 Correct 501 ms 86676 KB Output is correct
17 Correct 513 ms 86692 KB Output is correct
18 Correct 509 ms 86612 KB Output is correct
19 Correct 504 ms 86664 KB Output is correct
20 Correct 518 ms 86552 KB Output is correct
21 Correct 544 ms 86376 KB Output is correct
22 Correct 514 ms 83992 KB Output is correct
23 Correct 511 ms 86636 KB Output is correct
24 Correct 511 ms 85780 KB Output is correct
25 Correct 250 ms 35148 KB Output is correct
26 Correct 235 ms 33704 KB Output is correct
27 Correct 516 ms 86656 KB Output is correct
28 Correct 528 ms 84716 KB Output is correct
29 Correct 535 ms 86756 KB Output is correct
30 Correct 503 ms 86732 KB Output is correct
31 Correct 509 ms 85592 KB Output is correct
32 Correct 509 ms 86492 KB Output is correct
33 Correct 225 ms 33692 KB Output is correct
34 Correct 229 ms 34672 KB Output is correct
35 Correct 243 ms 33616 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 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 468 KB Output is correct
45 Correct 1 ms 476 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 472 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 596 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 432 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 1 ms 468 KB Output is correct
60 Correct 1 ms 304 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 2 ms 472 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 1 ms 432 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 340 KB Output is correct
70 Correct 1 ms 304 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 296 KB Output is correct
73 Correct 3 ms 596 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 2 ms 488 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 0 ms 292 KB Output is correct
78 Correct 1 ms 296 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 1 ms 436 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 3 ms 640 KB Output is correct
84 Correct 2 ms 596 KB Output is correct
85 Correct 3 ms 468 KB Output is correct
86 Correct 2 ms 564 KB Output is correct
87 Correct 2 ms 596 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Correct 2 ms 596 KB Output is correct
90 Correct 3 ms 596 KB Output is correct
91 Correct 3 ms 560 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 2 ms 596 KB Output is correct
96 Correct 3 ms 568 KB Output is correct
97 Correct 3 ms 596 KB Output is correct
98 Correct 2 ms 564 KB Output is correct
99 Correct 1 ms 468 KB Output is correct
100 Correct 1 ms 340 KB Output is correct
101 Correct 4 ms 596 KB Output is correct
102 Correct 2 ms 596 KB Output is correct
103 Correct 3 ms 596 KB Output is correct
104 Correct 3 ms 596 KB Output is correct
105 Correct 3 ms 564 KB Output is correct
106 Correct 0 ms 340 KB Output is correct
107 Correct 1 ms 340 KB Output is correct
108 Correct 1036 ms 74892 KB Output is correct
109 Correct 1085 ms 83900 KB Output is correct
110 Correct 471 ms 74816 KB Output is correct
111 Correct 539 ms 83908 KB Output is correct
112 Correct 3 ms 724 KB Output is correct
113 Correct 4 ms 692 KB Output is correct
114 Correct 746 ms 105556 KB Output is correct
115 Correct 688 ms 104028 KB Output is correct
116 Correct 517 ms 62524 KB Output is correct
117 Correct 595 ms 65968 KB Output is correct
118 Correct 569 ms 92556 KB Output is correct
119 Correct 198 ms 26104 KB Output is correct
120 Correct 830 ms 104808 KB Output is correct
121 Correct 772 ms 104668 KB Output is correct
122 Correct 766 ms 103276 KB Output is correct
123 Correct 751 ms 103156 KB Output is correct
124 Correct 757 ms 103348 KB Output is correct
125 Correct 743 ms 103780 KB Output is correct
126 Correct 738 ms 103128 KB Output is correct
127 Correct 653 ms 101672 KB Output is correct
128 Correct 756 ms 103220 KB Output is correct
129 Correct 724 ms 102816 KB Output is correct
130 Correct 266 ms 42016 KB Output is correct
131 Correct 254 ms 40660 KB Output is correct
132 Correct 749 ms 102468 KB Output is correct
133 Correct 290 ms 43908 KB Output is correct
134 Correct 757 ms 102996 KB Output is correct
135 Correct 742 ms 103584 KB Output is correct
136 Correct 742 ms 102652 KB Output is correct
137 Correct 762 ms 103480 KB Output is correct
138 Correct 318 ms 41312 KB Output is correct
139 Correct 267 ms 41540 KB Output is correct
140 Correct 298 ms 40328 KB Output is correct