#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n,m; cin>>n>>m;
vector<ll> a(n), b(n);
for (auto &i: a) cin>>i;
for (int i=0; i<n; i++) {
cin>>b[i];
a[i]=max(a[i],b[i]);
}
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
for (int i=0; i<n; i++) q.push({0ll,i});
vector<int> times(n,0);
for (int i=0; i<n*m; i++) {
auto t=q.top(); q.pop();
if (times[t.second]<m) {
t.first+=a[t.second];
times[t.second]++;
} else {
t.first+=b[t.second];
}
q.push(t);
}
cout<<q.top().first;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
416 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
198 ms |
14200 KB |
Output is correct |
12 |
Correct |
211 ms |
13672 KB |
Output is correct |
13 |
Correct |
149 ms |
15296 KB |
Output is correct |
14 |
Correct |
152 ms |
14700 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
95 ms |
14440 KB |
Output is correct |
17 |
Correct |
241 ms |
15208 KB |
Output is correct |
18 |
Correct |
193 ms |
15212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
95 ms |
14440 KB |
Output is correct |
3 |
Correct |
241 ms |
15208 KB |
Output is correct |
4 |
Correct |
193 ms |
15212 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 |
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 |
115 ms |
6992 KB |
Output is correct |
14 |
Correct |
104 ms |
4172 KB |
Output is correct |
15 |
Correct |
64 ms |
3780 KB |
Output is correct |
16 |
Correct |
70 ms |
2540 KB |
Output is correct |
17 |
Correct |
14 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
348 KB |
Output is correct |
22 |
Correct |
21 ms |
604 KB |
Output is correct |
23 |
Correct |
23 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
416 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
198 ms |
14200 KB |
Output is correct |
12 |
Correct |
211 ms |
13672 KB |
Output is correct |
13 |
Correct |
149 ms |
15296 KB |
Output is correct |
14 |
Correct |
152 ms |
14700 KB |
Output is correct |
15 |
Correct |
0 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 |
115 ms |
6992 KB |
Output is correct |
24 |
Correct |
104 ms |
4172 KB |
Output is correct |
25 |
Correct |
64 ms |
3780 KB |
Output is correct |
26 |
Correct |
70 ms |
2540 KB |
Output is correct |
27 |
Correct |
14 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
344 KB |
Output is correct |
29 |
Correct |
5 ms |
348 KB |
Output is correct |
30 |
Correct |
6 ms |
348 KB |
Output is correct |
31 |
Correct |
6 ms |
348 KB |
Output is correct |
32 |
Correct |
21 ms |
604 KB |
Output is correct |
33 |
Correct |
23 ms |
620 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
95 ms |
14440 KB |
Output is correct |
36 |
Correct |
241 ms |
15208 KB |
Output is correct |
37 |
Correct |
193 ms |
15212 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 |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
23 ms |
652 KB |
Output is correct |
46 |
Correct |
9 ms |
856 KB |
Output is correct |
47 |
Correct |
5 ms |
604 KB |
Output is correct |
48 |
Correct |
51 ms |
3272 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
16 ms |
432 KB |
Output is correct |
51 |
Correct |
27 ms |
744 KB |
Output is correct |
52 |
Correct |
6 ms |
344 KB |
Output is correct |
53 |
Correct |
9 ms |
600 KB |
Output is correct |
54 |
Correct |
13 ms |
348 KB |
Output is correct |
55 |
Correct |
144 ms |
10692 KB |
Output is correct |
56 |
Correct |
65 ms |
5424 KB |
Output is correct |
57 |
Correct |
65 ms |
5432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
115 ms |
6992 KB |
Output is correct |
10 |
Correct |
104 ms |
4172 KB |
Output is correct |
11 |
Correct |
64 ms |
3780 KB |
Output is correct |
12 |
Correct |
70 ms |
2540 KB |
Output is correct |
13 |
Correct |
14 ms |
348 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
348 KB |
Output is correct |
17 |
Correct |
6 ms |
348 KB |
Output is correct |
18 |
Correct |
21 ms |
604 KB |
Output is correct |
19 |
Correct |
23 ms |
620 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
95 ms |
14440 KB |
Output is correct |
22 |
Correct |
241 ms |
15208 KB |
Output is correct |
23 |
Correct |
193 ms |
15212 KB |
Output is correct |
24 |
Execution timed out |
1053 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
416 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
198 ms |
14200 KB |
Output is correct |
12 |
Correct |
211 ms |
13672 KB |
Output is correct |
13 |
Correct |
149 ms |
15296 KB |
Output is correct |
14 |
Correct |
152 ms |
14700 KB |
Output is correct |
15 |
Correct |
0 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 |
115 ms |
6992 KB |
Output is correct |
24 |
Correct |
104 ms |
4172 KB |
Output is correct |
25 |
Correct |
64 ms |
3780 KB |
Output is correct |
26 |
Correct |
70 ms |
2540 KB |
Output is correct |
27 |
Correct |
14 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
344 KB |
Output is correct |
29 |
Correct |
5 ms |
348 KB |
Output is correct |
30 |
Correct |
6 ms |
348 KB |
Output is correct |
31 |
Correct |
6 ms |
348 KB |
Output is correct |
32 |
Correct |
21 ms |
604 KB |
Output is correct |
33 |
Correct |
23 ms |
620 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 |
0 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 |
23 ms |
652 KB |
Output is correct |
42 |
Correct |
9 ms |
856 KB |
Output is correct |
43 |
Correct |
5 ms |
604 KB |
Output is correct |
44 |
Correct |
51 ms |
3272 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
16 ms |
432 KB |
Output is correct |
47 |
Correct |
27 ms |
744 KB |
Output is correct |
48 |
Correct |
6 ms |
344 KB |
Output is correct |
49 |
Correct |
9 ms |
600 KB |
Output is correct |
50 |
Correct |
13 ms |
348 KB |
Output is correct |
51 |
Correct |
144 ms |
10692 KB |
Output is correct |
52 |
Correct |
65 ms |
5424 KB |
Output is correct |
53 |
Correct |
65 ms |
5432 KB |
Output is correct |
54 |
Execution timed out |
1053 ms |
2260 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |