forked from drken1215/book_algorithm_solution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_3_4.cpp
More file actions
30 lines (26 loc) · 693 Bytes
/
code_3_4.cpp
File metadata and controls
30 lines (26 loc) · 693 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
const int INF = 20000000; // 十分大きな値に
int main() {
// 入力を受け取る
int N, K;
cin >> N >> K;
vector<int> a(N), b(N);
for (int i = 0; i < N; ++i) cin >> a[i];
for (int i = 0; i < N; ++i) cin >> b[i];
// 線形探索
int min_value = INF;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
// 和が K 未満の場合はスキップ
if (a[i] + b[j] < K) continue;
// 最小値を更新
if (a[i] + b[j] < min_value) {
min_value = a[i] + b[j];
}
}
}
// 結果出力
cout << min_value << endl;
}