// oj.uz SELF STUDY (JOI22_HO_T2)
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MAX_NUM = 2 * 1e9 * 1e9; // Ai or Bi * M, 2 is because (l + r) / 2
int N, M;
vector<pair<int, int>> vec;
bool ifFail(const ll passline) {
ll comprehension = 0;
int cnt_course = 0;
int cnt = M;
ll t = N * M;
while(t--) {
if(comprehension < passline) {
if(vec[cnt_course].first > vec[cnt_course].second && cnt > 0) {
comprehension += vec[cnt_course].first;
cnt--;
} else comprehension += vec[cnt_course].second;
}
if(comprehension >= passline) {
// cout << comprehension << '\n';
cnt_course++;
comprehension = 0;
cnt = M;
}
}
// cout << passline << ' ' << cnt_course << '\n';
return cnt_course < N;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N >> M;
vec.resize(N);
for(auto &i : vec) cin >> i.first;
for(auto &i : vec) cin >> i.second;
ll l = 1, r = MAX_NUM;
while(l < r) {
ll mid = (l + r) / 2 + 1;
if(ifFail(mid)) {
r = mid - 1;
}
else {
l = mid;
}
}
cout << l << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
125 ms |
8424 KB |
Output is correct |
12 |
Correct |
116 ms |
8528 KB |
Output is correct |
13 |
Correct |
61 ms |
6488 KB |
Output is correct |
14 |
Correct |
64 ms |
6360 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
43 ms |
3948 KB |
Output is correct |
17 |
Correct |
74 ms |
9040 KB |
Output is correct |
18 |
Correct |
71 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
43 ms |
3948 KB |
Output is correct |
3 |
Correct |
74 ms |
9040 KB |
Output is correct |
4 |
Correct |
71 ms |
8528 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 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 |
54 ms |
4436 KB |
Output is correct |
14 |
Correct |
46 ms |
3160 KB |
Output is correct |
15 |
Correct |
60 ms |
2456 KB |
Output is correct |
16 |
Correct |
50 ms |
1884 KB |
Output is correct |
17 |
Correct |
27 ms |
348 KB |
Output is correct |
18 |
Correct |
18 ms |
344 KB |
Output is correct |
19 |
Correct |
35 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
348 KB |
Output is correct |
21 |
Correct |
41 ms |
348 KB |
Output is correct |
22 |
Correct |
19 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
125 ms |
8424 KB |
Output is correct |
12 |
Correct |
116 ms |
8528 KB |
Output is correct |
13 |
Correct |
61 ms |
6488 KB |
Output is correct |
14 |
Correct |
64 ms |
6360 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 |
344 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 |
54 ms |
4436 KB |
Output is correct |
24 |
Correct |
46 ms |
3160 KB |
Output is correct |
25 |
Correct |
60 ms |
2456 KB |
Output is correct |
26 |
Correct |
50 ms |
1884 KB |
Output is correct |
27 |
Correct |
27 ms |
348 KB |
Output is correct |
28 |
Correct |
18 ms |
344 KB |
Output is correct |
29 |
Correct |
35 ms |
348 KB |
Output is correct |
30 |
Correct |
18 ms |
348 KB |
Output is correct |
31 |
Correct |
41 ms |
348 KB |
Output is correct |
32 |
Correct |
19 ms |
348 KB |
Output is correct |
33 |
Correct |
26 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
43 ms |
3948 KB |
Output is correct |
36 |
Correct |
74 ms |
9040 KB |
Output is correct |
37 |
Correct |
71 ms |
8528 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
452 KB |
Output is correct |
44 |
Correct |
0 ms |
344 KB |
Output is correct |
45 |
Correct |
25 ms |
596 KB |
Output is correct |
46 |
Correct |
7 ms |
692 KB |
Output is correct |
47 |
Correct |
6 ms |
344 KB |
Output is correct |
48 |
Correct |
30 ms |
1628 KB |
Output is correct |
49 |
Correct |
3 ms |
348 KB |
Output is correct |
50 |
Correct |
35 ms |
344 KB |
Output is correct |
51 |
Correct |
30 ms |
348 KB |
Output is correct |
52 |
Correct |
29 ms |
344 KB |
Output is correct |
53 |
Correct |
24 ms |
344 KB |
Output is correct |
54 |
Correct |
45 ms |
436 KB |
Output is correct |
55 |
Correct |
84 ms |
4436 KB |
Output is correct |
56 |
Correct |
36 ms |
2396 KB |
Output is correct |
57 |
Correct |
45 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 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 |
54 ms |
4436 KB |
Output is correct |
10 |
Correct |
46 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
2456 KB |
Output is correct |
12 |
Correct |
50 ms |
1884 KB |
Output is correct |
13 |
Correct |
27 ms |
348 KB |
Output is correct |
14 |
Correct |
18 ms |
344 KB |
Output is correct |
15 |
Correct |
35 ms |
348 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
41 ms |
348 KB |
Output is correct |
18 |
Correct |
19 ms |
348 KB |
Output is correct |
19 |
Correct |
26 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
43 ms |
3948 KB |
Output is correct |
22 |
Correct |
74 ms |
9040 KB |
Output is correct |
23 |
Correct |
71 ms |
8528 KB |
Output is correct |
24 |
Execution timed out |
1061 ms |
1628 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
125 ms |
8424 KB |
Output is correct |
12 |
Correct |
116 ms |
8528 KB |
Output is correct |
13 |
Correct |
61 ms |
6488 KB |
Output is correct |
14 |
Correct |
64 ms |
6360 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 |
344 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 |
54 ms |
4436 KB |
Output is correct |
24 |
Correct |
46 ms |
3160 KB |
Output is correct |
25 |
Correct |
60 ms |
2456 KB |
Output is correct |
26 |
Correct |
50 ms |
1884 KB |
Output is correct |
27 |
Correct |
27 ms |
348 KB |
Output is correct |
28 |
Correct |
18 ms |
344 KB |
Output is correct |
29 |
Correct |
35 ms |
348 KB |
Output is correct |
30 |
Correct |
18 ms |
348 KB |
Output is correct |
31 |
Correct |
41 ms |
348 KB |
Output is correct |
32 |
Correct |
19 ms |
348 KB |
Output is correct |
33 |
Correct |
26 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
452 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
25 ms |
596 KB |
Output is correct |
42 |
Correct |
7 ms |
692 KB |
Output is correct |
43 |
Correct |
6 ms |
344 KB |
Output is correct |
44 |
Correct |
30 ms |
1628 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
35 ms |
344 KB |
Output is correct |
47 |
Correct |
30 ms |
348 KB |
Output is correct |
48 |
Correct |
29 ms |
344 KB |
Output is correct |
49 |
Correct |
24 ms |
344 KB |
Output is correct |
50 |
Correct |
45 ms |
436 KB |
Output is correct |
51 |
Correct |
84 ms |
4436 KB |
Output is correct |
52 |
Correct |
36 ms |
2396 KB |
Output is correct |
53 |
Correct |
45 ms |
2396 KB |
Output is correct |
54 |
Execution timed out |
1061 ms |
1628 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |