#include <iostream>
#include <set>
#define int long long
using namespace std;
const int nmax = 3e5 + 7;
int v[nmax], b[nmax];
struct pairing {
int first, second;
const bool operator < (pairing a) const {
if(first != a.first) {
return first < a.first;
} else {
return second > a.second;
}
}
};
int32_t main() {
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i ++) {
cin >> v[i];
}
for(int i = 1; i <= n; i ++){
cin >> b[i];
}
set<pairing> pq;
for(int i = 1; i <= n; i ++) {
pq.insert({max(v[i], b[i]), i});
}
for(int i = 2; i <= k; i ++) {
for(int j = 1; j <= n; j ++) {
pairing curr = *(pq.begin());
int sum = curr.first, ind = curr.second;
if(pq.find({sum, j}) != pq.end()) {
ind = j;
}
pq.erase({sum, ind});
if(j == ind) {
sum += max(v[j], b[j]);
} else {
sum += b[ind];
}
pq.insert({sum, ind});
}
}
int minn = 1e18;
for(auto it : pq) {
// cout << it.first << " " << it.second << endl;
minn = min(minn, it.first);
}
cout << minn;
return 0;
}
# |
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 |
1 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 |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
290 ms |
23728 KB |
Output is correct |
12 |
Correct |
291 ms |
23692 KB |
Output is correct |
13 |
Correct |
184 ms |
23692 KB |
Output is correct |
14 |
Correct |
184 ms |
23764 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
127 ms |
23756 KB |
Output is correct |
17 |
Correct |
246 ms |
23716 KB |
Output is correct |
18 |
Correct |
291 ms |
23656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
127 ms |
23756 KB |
Output is correct |
3 |
Correct |
246 ms |
23716 KB |
Output is correct |
4 |
Correct |
291 ms |
23656 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
157 ms |
11960 KB |
Output is correct |
14 |
Correct |
152 ms |
8012 KB |
Output is correct |
15 |
Correct |
85 ms |
6164 KB |
Output is correct |
16 |
Correct |
97 ms |
4984 KB |
Output is correct |
17 |
Correct |
33 ms |
340 KB |
Output is correct |
18 |
Correct |
25 ms |
312 KB |
Output is correct |
19 |
Correct |
21 ms |
212 KB |
Output is correct |
20 |
Correct |
12 ms |
308 KB |
Output is correct |
21 |
Correct |
12 ms |
312 KB |
Output is correct |
22 |
Correct |
64 ms |
660 KB |
Output is correct |
23 |
Correct |
67 ms |
596 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 |
1 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 |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
290 ms |
23728 KB |
Output is correct |
12 |
Correct |
291 ms |
23692 KB |
Output is correct |
13 |
Correct |
184 ms |
23692 KB |
Output is correct |
14 |
Correct |
184 ms |
23764 KB |
Output is correct |
15 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
157 ms |
11960 KB |
Output is correct |
24 |
Correct |
152 ms |
8012 KB |
Output is correct |
25 |
Correct |
85 ms |
6164 KB |
Output is correct |
26 |
Correct |
97 ms |
4984 KB |
Output is correct |
27 |
Correct |
33 ms |
340 KB |
Output is correct |
28 |
Correct |
25 ms |
312 KB |
Output is correct |
29 |
Correct |
21 ms |
212 KB |
Output is correct |
30 |
Correct |
12 ms |
308 KB |
Output is correct |
31 |
Correct |
12 ms |
312 KB |
Output is correct |
32 |
Correct |
64 ms |
660 KB |
Output is correct |
33 |
Correct |
67 ms |
596 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
127 ms |
23756 KB |
Output is correct |
36 |
Correct |
246 ms |
23716 KB |
Output is correct |
37 |
Correct |
291 ms |
23656 KB |
Output is correct |
38 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
39 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
157 ms |
11960 KB |
Output is correct |
10 |
Correct |
152 ms |
8012 KB |
Output is correct |
11 |
Correct |
85 ms |
6164 KB |
Output is correct |
12 |
Correct |
97 ms |
4984 KB |
Output is correct |
13 |
Correct |
33 ms |
340 KB |
Output is correct |
14 |
Correct |
25 ms |
312 KB |
Output is correct |
15 |
Correct |
21 ms |
212 KB |
Output is correct |
16 |
Correct |
12 ms |
308 KB |
Output is correct |
17 |
Correct |
12 ms |
312 KB |
Output is correct |
18 |
Correct |
64 ms |
660 KB |
Output is correct |
19 |
Correct |
67 ms |
596 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
127 ms |
23756 KB |
Output is correct |
22 |
Correct |
246 ms |
23716 KB |
Output is correct |
23 |
Correct |
291 ms |
23656 KB |
Output is correct |
24 |
Execution timed out |
1060 ms |
3820 KB |
Time limit exceeded |
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 |
1 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 |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
290 ms |
23728 KB |
Output is correct |
12 |
Correct |
291 ms |
23692 KB |
Output is correct |
13 |
Correct |
184 ms |
23692 KB |
Output is correct |
14 |
Correct |
184 ms |
23764 KB |
Output is correct |
15 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
157 ms |
11960 KB |
Output is correct |
24 |
Correct |
152 ms |
8012 KB |
Output is correct |
25 |
Correct |
85 ms |
6164 KB |
Output is correct |
26 |
Correct |
97 ms |
4984 KB |
Output is correct |
27 |
Correct |
33 ms |
340 KB |
Output is correct |
28 |
Correct |
25 ms |
312 KB |
Output is correct |
29 |
Correct |
21 ms |
212 KB |
Output is correct |
30 |
Correct |
12 ms |
308 KB |
Output is correct |
31 |
Correct |
12 ms |
312 KB |
Output is correct |
32 |
Correct |
64 ms |
660 KB |
Output is correct |
33 |
Correct |
67 ms |
596 KB |
Output is correct |
34 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |