#include <bits/stdc++.h>
#define int long long
using namespace std;
void open(){
if(fopen("input.inp", "r")){
freopen("input.inp", "r", stdin);
//freopen("output.out", "w", stdout);
}
}
const int maxn = 3e5 + 5;
int n, m;
int A[maxn], B[maxn];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
open();
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> A[i];
}
for(int i = 1; i <= n; i++){
cin >> B[i];
}
if(m == 1){
int result = 1e9 + 7;
for(int i = 1; i <= n; i++){
result = min(result, max(A[i], B[i]));
}
cout << result << endl;
return 0;
}
if(m * n <= maxn){
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for(int i = 1; i <= n; i++){
pq.push({0, i});
}
while(m--){
int temp = n;
vector<bool> check(n + 1, false);
while(temp--){
pair<int, int> first = pq.top();
pq.pop();
int old_val = first.first;
int pos = first.second;
if(A[pos] > B[pos] && !check[pos]){
check[pos] = true;
old_val += A[pos];
}else{
old_val += B[pos];
}
pq.push({old_val, pos});
}
}
cout << pq.top().first << endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'void open()':
Main.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | freopen("input.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
48 ms |
4916 KB |
Output is correct |
12 |
Correct |
46 ms |
4940 KB |
Output is correct |
13 |
Correct |
51 ms |
4964 KB |
Output is correct |
14 |
Correct |
37 ms |
4924 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
29 ms |
4956 KB |
Output is correct |
17 |
Correct |
48 ms |
4940 KB |
Output is correct |
18 |
Correct |
45 ms |
4928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
29 ms |
4956 KB |
Output is correct |
3 |
Correct |
48 ms |
4940 KB |
Output is correct |
4 |
Correct |
45 ms |
4928 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
54 ms |
6864 KB |
Output is correct |
14 |
Correct |
44 ms |
4016 KB |
Output is correct |
15 |
Correct |
33 ms |
3600 KB |
Output is correct |
16 |
Correct |
44 ms |
2436 KB |
Output is correct |
17 |
Correct |
13 ms |
376 KB |
Output is correct |
18 |
Correct |
11 ms |
212 KB |
Output is correct |
19 |
Correct |
6 ms |
336 KB |
Output is correct |
20 |
Correct |
10 ms |
328 KB |
Output is correct |
21 |
Correct |
9 ms |
212 KB |
Output is correct |
22 |
Correct |
18 ms |
596 KB |
Output is correct |
23 |
Correct |
18 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
48 ms |
4916 KB |
Output is correct |
12 |
Correct |
46 ms |
4940 KB |
Output is correct |
13 |
Correct |
51 ms |
4964 KB |
Output is correct |
14 |
Correct |
37 ms |
4924 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
54 ms |
6864 KB |
Output is correct |
24 |
Correct |
44 ms |
4016 KB |
Output is correct |
25 |
Correct |
33 ms |
3600 KB |
Output is correct |
26 |
Correct |
44 ms |
2436 KB |
Output is correct |
27 |
Correct |
13 ms |
376 KB |
Output is correct |
28 |
Correct |
11 ms |
212 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
10 ms |
328 KB |
Output is correct |
31 |
Correct |
9 ms |
212 KB |
Output is correct |
32 |
Correct |
18 ms |
596 KB |
Output is correct |
33 |
Correct |
18 ms |
616 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
29 ms |
4956 KB |
Output is correct |
36 |
Correct |
48 ms |
4940 KB |
Output is correct |
37 |
Correct |
45 ms |
4928 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
21 ms |
728 KB |
Output is correct |
46 |
Incorrect |
5 ms |
980 KB |
Output isn't correct |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
54 ms |
6864 KB |
Output is correct |
10 |
Correct |
44 ms |
4016 KB |
Output is correct |
11 |
Correct |
33 ms |
3600 KB |
Output is correct |
12 |
Correct |
44 ms |
2436 KB |
Output is correct |
13 |
Correct |
13 ms |
376 KB |
Output is correct |
14 |
Correct |
11 ms |
212 KB |
Output is correct |
15 |
Correct |
6 ms |
336 KB |
Output is correct |
16 |
Correct |
10 ms |
328 KB |
Output is correct |
17 |
Correct |
9 ms |
212 KB |
Output is correct |
18 |
Correct |
18 ms |
596 KB |
Output is correct |
19 |
Correct |
18 ms |
616 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
29 ms |
4956 KB |
Output is correct |
22 |
Correct |
48 ms |
4940 KB |
Output is correct |
23 |
Correct |
45 ms |
4928 KB |
Output is correct |
24 |
Incorrect |
7 ms |
980 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
48 ms |
4916 KB |
Output is correct |
12 |
Correct |
46 ms |
4940 KB |
Output is correct |
13 |
Correct |
51 ms |
4964 KB |
Output is correct |
14 |
Correct |
37 ms |
4924 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
54 ms |
6864 KB |
Output is correct |
24 |
Correct |
44 ms |
4016 KB |
Output is correct |
25 |
Correct |
33 ms |
3600 KB |
Output is correct |
26 |
Correct |
44 ms |
2436 KB |
Output is correct |
27 |
Correct |
13 ms |
376 KB |
Output is correct |
28 |
Correct |
11 ms |
212 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
10 ms |
328 KB |
Output is correct |
31 |
Correct |
9 ms |
212 KB |
Output is correct |
32 |
Correct |
18 ms |
596 KB |
Output is correct |
33 |
Correct |
18 ms |
616 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
300 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
21 ms |
728 KB |
Output is correct |
42 |
Incorrect |
5 ms |
980 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |