-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Death_s_Blessing.cpp
More file actions
55 lines (47 loc) · 1.34 KB
/
B_Death_s_Blessing.cpp
File metadata and controls
55 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <algorithm>
#include <bits/stdc++.h>
#include <ios>
#include <iostream>
#include <ostream>
#include <shared_mutex>
#include <utility>
#include <vector>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int testCases;
cin >> testCases;
while(testCases--){
int numMonsters;
cin >> numMonsters;
vector<long long> h(numMonsters);
vector<long long> time(numMonsters);
for(int i = 0; i < numMonsters; ++i){
cin >> h[i];
}
for (int i = 0; i < numMonsters; ++i) {
cin >> time[i];
}
// if(numMonsters < 3){
// long long timeTokill = h[0];
// timeTokill += h[1] + time[0];
// cout << timeTokill << endl;
// // break;
// }
vector<pair<long,long>> pairs;
for(int i = 0 ; i < numMonsters; ++i){
pairs.push_back({h[i],time[i]});
}
sort(pairs.begin(),pairs.end(),[](const pair<long, long>& a, const pair<long,long>& b){
return a.second < b.second;
});
long long timeTokill = pairs[0].first;
for(int i = 1; i < numMonsters; ++i){
timeTokill += pairs[i].first + pairs[i -1].second;
}
cout << timeTokill << endl;
}
return 0;
}