Submission #544811

# Submission time Handle Problem Language Result Execution time Memory
544811 2022-04-02T18:41:55 Z blue Self Study (JOI22_ho_t2) C++17
100 / 100
345 ms 13832 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

using pii = pair<int, int>;
using vpii = vector<pii>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define sz(x) int(x.size())

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N, M;
	cin >> N >> M;

	vll A(1+N), B(1+N);
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= N; i++)
	{
		cin >> B[i];
		A[i] = max(A[i], B[i]);
	}

	ll lo = 0, hi = 1'000'000'000'000'000'000LL;

	while(lo != hi)
	{
		ll target = (lo+hi)/2 + 1;

		vll remaining_goal(1+N);
		ll remaining_slots = 0;

		for(int i = 1; i <= N; i++)
		{
			ll classes = min(M, (target / A[i]) + bool(target % A[i]));

			remaining_goal[i] = max(0LL, target - classes * A[i]);
			remaining_slots += M - classes;
		}

		for(int i = 1; i <= N; i++)
		{
			ll curr = (remaining_goal[i] / B[i])  +  bool(remaining_goal[i] % B[i]);
			remaining_slots -= curr;
			if(remaining_slots < 0)
			{
				break;
			}
		}

		// cerr << target << " : " << remaining_slots << '\n';

		if(remaining_slots >= 0)
			lo = target;
		else
			hi = target - 1;
	}

	cout << lo << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 3 ms 480 KB Output is correct
11 Correct 196 ms 13164 KB Output is correct
12 Correct 188 ms 13156 KB Output is correct
13 Correct 188 ms 11184 KB Output is correct
14 Correct 193 ms 11148 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 207 ms 8580 KB Output is correct
17 Correct 210 ms 13796 KB Output is correct
18 Correct 194 ms 13156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 207 ms 8580 KB Output is correct
3 Correct 210 ms 13796 KB Output is correct
4 Correct 194 ms 13156 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 108 ms 6736 KB Output is correct
14 Correct 76 ms 4588 KB Output is correct
15 Correct 54 ms 3552 KB Output is correct
16 Correct 45 ms 2888 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 3 ms 480 KB Output is correct
11 Correct 196 ms 13164 KB Output is correct
12 Correct 188 ms 13156 KB Output is correct
13 Correct 188 ms 11184 KB Output is correct
14 Correct 193 ms 11148 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 108 ms 6736 KB Output is correct
24 Correct 76 ms 4588 KB Output is correct
25 Correct 54 ms 3552 KB Output is correct
26 Correct 45 ms 2888 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 207 ms 8580 KB Output is correct
36 Correct 210 ms 13796 KB Output is correct
37 Correct 194 ms 13156 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 5 ms 468 KB Output is correct
46 Correct 7 ms 636 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 38 ms 2516 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 5 ms 460 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 320 KB Output is correct
55 Correct 110 ms 6684 KB Output is correct
56 Correct 66 ms 3924 KB Output is correct
57 Correct 66 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 108 ms 6736 KB Output is correct
10 Correct 76 ms 4588 KB Output is correct
11 Correct 54 ms 3552 KB Output is correct
12 Correct 45 ms 2888 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 207 ms 8580 KB Output is correct
22 Correct 210 ms 13796 KB Output is correct
23 Correct 194 ms 13156 KB Output is correct
24 Correct 49 ms 2300 KB Output is correct
25 Correct 140 ms 5980 KB Output is correct
26 Correct 28 ms 1628 KB Output is correct
27 Correct 212 ms 13156 KB Output is correct
28 Correct 219 ms 13148 KB Output is correct
29 Correct 220 ms 13280 KB Output is correct
30 Correct 251 ms 13280 KB Output is correct
31 Correct 331 ms 13216 KB Output is correct
32 Correct 262 ms 8540 KB Output is correct
33 Correct 345 ms 13832 KB Output is correct
34 Correct 275 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 3 ms 480 KB Output is correct
11 Correct 196 ms 13164 KB Output is correct
12 Correct 188 ms 13156 KB Output is correct
13 Correct 188 ms 11184 KB Output is correct
14 Correct 193 ms 11148 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 108 ms 6736 KB Output is correct
24 Correct 76 ms 4588 KB Output is correct
25 Correct 54 ms 3552 KB Output is correct
26 Correct 45 ms 2888 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
41 Correct 5 ms 468 KB Output is correct
42 Correct 7 ms 636 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 38 ms 2516 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 5 ms 460 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 320 KB Output is correct
51 Correct 110 ms 6684 KB Output is correct
52 Correct 66 ms 3924 KB Output is correct
53 Correct 66 ms 3928 KB Output is correct
54 Correct 49 ms 2300 KB Output is correct
55 Correct 140 ms 5980 KB Output is correct
56 Correct 28 ms 1628 KB Output is correct
57 Correct 212 ms 13156 KB Output is correct
58 Correct 219 ms 13148 KB Output is correct
59 Correct 220 ms 13280 KB Output is correct
60 Correct 251 ms 13280 KB Output is correct
61 Correct 331 ms 13216 KB Output is correct
62 Correct 262 ms 8540 KB Output is correct
63 Correct 345 ms 13832 KB Output is correct
64 Correct 275 ms 8528 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 207 ms 8580 KB Output is correct
67 Correct 210 ms 13796 KB Output is correct
68 Correct 194 ms 13156 KB Output is correct
69 Correct 33 ms 1620 KB Output is correct
70 Correct 9 ms 584 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 46 ms 2168 KB Output is correct
73 Correct 11 ms 740 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 228 ms 13156 KB Output is correct
76 Correct 239 ms 13172 KB Output is correct
77 Correct 261 ms 13168 KB Output is correct
78 Correct 290 ms 13224 KB Output is correct
79 Correct 324 ms 13276 KB Output is correct
80 Correct 321 ms 13160 KB Output is correct
81 Correct 317 ms 11144 KB Output is correct
82 Correct 320 ms 11228 KB Output is correct