Skip to content

Commit 201bee1

Browse files
committed
알고스팟_점심_도시락
1 parent 03e4e9d commit 201bee1

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int func(vector<int>& l, vector<int>& e){
8+
int n = l.size();
9+
vector<pair<int,int>> pairs;
10+
pairs.resize(n);
11+
12+
for(int i=0; i < n; i++){
13+
pairs[i] = make_pair(e[i],l[i]);
14+
}
15+
16+
// 먹는 시간 기준 내림 차순으로 정렬한다
17+
sort(pairs.begin(),pairs.end(),greater<pair<int,int>>());
18+
19+
int ret = 0 ,start = 0;
20+
for(int i=0; i < n; i++ ){
21+
int launch = pairs[i].second;
22+
start += launch; // 현재까지 데우는 데 걸리는 시간을 누적한다.
23+
ret = max(ret, start + e[i]); // ret와 다 데우고 난 다음 먹는 시간 중 최대 값을 고른다.
24+
}
25+
26+
return ret;
27+
}
28+
29+
int main(void){
30+
ios::sync_with_stdio(0);
31+
cin.tie(0);
32+
33+
int cc;
34+
cin >> cc;
35+
for(int c=0; c < cc; c++){
36+
vector<int> launches;
37+
vector<int> eats;
38+
int n = -1;
39+
cin >> n;
40+
launches.resize(n);
41+
eats.resize(n);
42+
43+
for(int i=0; i < n; i++){
44+
cin >> launches[i];
45+
}
46+
47+
for(int i=0; i < n; i++){
48+
cin >> eats[i];
49+
}
50+
51+
cout << func(launches,eats) << endl;
52+
}
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)