-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwoArrays.cpp
More file actions
45 lines (35 loc) · 934 Bytes
/
twoArrays.cpp
File metadata and controls
45 lines (35 loc) · 934 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int n, m;
cin >> n >> m;
int matr[n+1][m+1];
vector<vector<bool>> seen(n+1, vector <bool> (10e9+1, false));
int w[n+1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> matr[i][j];
if (!seen[i][matr[i][j]]) {
seen[i][matr[i][j]] = true;
}
}
cin >> w[i];
}
int minima = INT_MAX;
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= n; j++) {
bool found = false;
for (int k = 1; k <= m; k++) {
if (seen[j][matr[i][k]]) {
found = true;
break;
}
}
if (!found) minima = min(minima, w[i]+w[j]);
}
}
if (minima != INT_MAX) cout << minima << "\n";
else cout << -1 << "\n";
}