#include <vector>
#include <iostream>
using namespace std;
long long n, m;
vector<int> course;
vector<int> study;
bool works(long long target) {
vector<long long> vals(n); // value of each class rn
long long hours = n * m;
long long temp;
long long left = 0;
for (int i = 0; i < n; i++) {
if (course[i] > study[i]) {
temp = target / course[i];
if (target % course[i] != 0) {
temp++;
}
temp = min(temp, m);
hours -= temp;
vals[i] += course[i] * temp;
}
if (vals[i] < target) {
left = target - vals[i];
temp = left / study[i];
if (left % study[i] != 0) {
temp++;
}
hours -= temp;
vals[i] += temp * study[i];
}
if (hours < 0) {
return false;
}
// cout << hours << ' ';
}
return true;
}
int main() {
cin >> n >> m;
course.resize(n);
study.resize(n);
for (int i = 0; i < n; i++) {
cin >> course[i];
}
for (int i = 0; i < n; i++) {
cin >> study[i];
}
// binary search for max min comprehension lvl
long long low = 0;
long long high = 1e18;
long long mid;
long long working = 0;
while (low <= high) {
mid = (low + high) / 2;
if (works(mid)) {
working = mid;
low = mid + 1;
}
else {
high = mid - 1;
}
}
cout << working;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
198 ms |
10820 KB |
Output is correct |
12 |
Correct |
194 ms |
10832 KB |
Output is correct |
13 |
Correct |
125 ms |
8784 KB |
Output is correct |
14 |
Correct |
128 ms |
9044 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
53 ms |
6228 KB |
Output is correct |
17 |
Correct |
178 ms |
11564 KB |
Output is correct |
18 |
Correct |
169 ms |
10700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
53 ms |
6228 KB |
Output is correct |
3 |
Correct |
178 ms |
11564 KB |
Output is correct |
4 |
Correct |
169 ms |
10700 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
88 ms |
5524 KB |
Output is correct |
14 |
Correct |
60 ms |
3908 KB |
Output is correct |
15 |
Correct |
47 ms |
2904 KB |
Output is correct |
16 |
Correct |
37 ms |
2340 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
198 ms |
10820 KB |
Output is correct |
12 |
Correct |
194 ms |
10832 KB |
Output is correct |
13 |
Correct |
125 ms |
8784 KB |
Output is correct |
14 |
Correct |
128 ms |
9044 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
88 ms |
5524 KB |
Output is correct |
24 |
Correct |
60 ms |
3908 KB |
Output is correct |
25 |
Correct |
47 ms |
2904 KB |
Output is correct |
26 |
Correct |
37 ms |
2340 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
53 ms |
6228 KB |
Output is correct |
36 |
Correct |
178 ms |
11564 KB |
Output is correct |
37 |
Correct |
169 ms |
10700 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
604 KB |
Output is correct |
46 |
Correct |
6 ms |
672 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
50 ms |
2224 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
3 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
103 ms |
5532 KB |
Output is correct |
56 |
Correct |
44 ms |
3128 KB |
Output is correct |
57 |
Correct |
42 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
88 ms |
5524 KB |
Output is correct |
10 |
Correct |
60 ms |
3908 KB |
Output is correct |
11 |
Correct |
47 ms |
2904 KB |
Output is correct |
12 |
Correct |
37 ms |
2340 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
53 ms |
6228 KB |
Output is correct |
22 |
Correct |
178 ms |
11564 KB |
Output is correct |
23 |
Correct |
169 ms |
10700 KB |
Output is correct |
24 |
Correct |
31 ms |
2276 KB |
Output is correct |
25 |
Correct |
85 ms |
5056 KB |
Output is correct |
26 |
Correct |
19 ms |
1376 KB |
Output is correct |
27 |
Correct |
175 ms |
10832 KB |
Output is correct |
28 |
Correct |
200 ms |
10836 KB |
Output is correct |
29 |
Correct |
179 ms |
10832 KB |
Output is correct |
30 |
Correct |
182 ms |
10832 KB |
Output is correct |
31 |
Correct |
207 ms |
10772 KB |
Output is correct |
32 |
Correct |
73 ms |
6228 KB |
Output is correct |
33 |
Correct |
203 ms |
11544 KB |
Output is correct |
34 |
Correct |
73 ms |
6100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
198 ms |
10820 KB |
Output is correct |
12 |
Correct |
194 ms |
10832 KB |
Output is correct |
13 |
Correct |
125 ms |
8784 KB |
Output is correct |
14 |
Correct |
128 ms |
9044 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
88 ms |
5524 KB |
Output is correct |
24 |
Correct |
60 ms |
3908 KB |
Output is correct |
25 |
Correct |
47 ms |
2904 KB |
Output is correct |
26 |
Correct |
37 ms |
2340 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
3 ms |
604 KB |
Output is correct |
42 |
Correct |
6 ms |
672 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
50 ms |
2224 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
3 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
103 ms |
5532 KB |
Output is correct |
52 |
Correct |
44 ms |
3128 KB |
Output is correct |
53 |
Correct |
42 ms |
3160 KB |
Output is correct |
54 |
Correct |
31 ms |
2276 KB |
Output is correct |
55 |
Correct |
85 ms |
5056 KB |
Output is correct |
56 |
Correct |
19 ms |
1376 KB |
Output is correct |
57 |
Correct |
175 ms |
10832 KB |
Output is correct |
58 |
Correct |
200 ms |
10836 KB |
Output is correct |
59 |
Correct |
179 ms |
10832 KB |
Output is correct |
60 |
Correct |
182 ms |
10832 KB |
Output is correct |
61 |
Correct |
207 ms |
10772 KB |
Output is correct |
62 |
Correct |
73 ms |
6228 KB |
Output is correct |
63 |
Correct |
203 ms |
11544 KB |
Output is correct |
64 |
Correct |
73 ms |
6100 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
53 ms |
6228 KB |
Output is correct |
67 |
Correct |
178 ms |
11564 KB |
Output is correct |
68 |
Correct |
169 ms |
10700 KB |
Output is correct |
69 |
Correct |
25 ms |
1560 KB |
Output is correct |
70 |
Correct |
6 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
440 KB |
Output is correct |
72 |
Correct |
35 ms |
1884 KB |
Output is correct |
73 |
Correct |
7 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
208 ms |
10700 KB |
Output is correct |
76 |
Correct |
208 ms |
10828 KB |
Output is correct |
77 |
Correct |
214 ms |
10900 KB |
Output is correct |
78 |
Correct |
239 ms |
10700 KB |
Output is correct |
79 |
Correct |
248 ms |
10836 KB |
Output is correct |
80 |
Correct |
252 ms |
10820 KB |
Output is correct |
81 |
Correct |
148 ms |
8788 KB |
Output is correct |
82 |
Correct |
153 ms |
8788 KB |
Output is correct |