-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3633.cpp
More file actions
23 lines (23 loc) · 884 Bytes
/
3633.cpp
File metadata and controls
23 lines (23 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
int earliestFinishTime(vector<int>& landStartTime, vector<int>& landDuration, vector<int>& waterStartTime, vector<int>& waterDuration) {
int n = landStartTime.size();
int m = waterStartTime.size();
int res = INT_MAX;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int lst = landStartTime[i];
int let = lst + landDuration[i];
int wst = waterStartTime[j];
int wet = wst + waterDuration[j];
// land -> water
if (let <= wst) res = min(res, wet);
else res = min(res, let + waterDuration[j]);
// water -> land
if (wet <= lst) res = min(res, let);
else res = min(res, wet + landDuration[i]);
}
}
return res;
}
};