-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_success_1.cpp
More file actions
71 lines (62 loc) · 1.14 KB
/
Copy pathB_success_1.cpp
File metadata and controls
71 lines (62 loc) · 1.14 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include<vector>
#include <istream>
#include<iomanip>
#include<stack>
using namespace std;
struct item {
int tid;
int x;
int y;
item(){}
item(int _tid, int _x, int _y) {
tid = _tid;
x = _x;
y = _y;
}
void scan() {
cin >> tid >> x >> y;
}
};
int lenght(int x, int y, int x1, int y1) {
return abs(x - x1) + abs(y - y1);
}
bool cmp(item a, item b) {
return a.x < b.x || a.x == b.x && a.y < b.y;
}
int main(){
int n, m;
cin >> n >> m;
vector<item> A(n), B(m);
for (int i = 0; i < n; i++) {
A[i].scan();
}
for (int i = 0; i < m; i++) {
B[i].scan();
}
sort(B.begin(), B.end(), cmp);
int ans = 1e9;
int x = 0, y = 0;
for (int i = 0; i < m; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
int l = lenght(A[j].x, A[j].y, B[i].x, B[i].y);
if (A[j].tid != B[i].tid)
l = l * 2;
cnt += l;
}
if (ans > cnt) {
ans = cnt;
x = B[i].x;
y = B[i].y;
}
}
cout << ans << '\n';
// cout << x << " " << y << '\n';
return 0;
}