Repository navigation
Expand file tree
/
Copy pathAmazingRace.cpp
More file actions
88 lines (88 loc) · 1.65 KB
/
Copy pathAmazingRace.cpp
File metadata and controls
88 lines (88 loc) · 1.65 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#define ll long long
#define pb push_back
#define vi vector<int>
#include<bits/stdc++.h>
const int N = 300;
using namespace std;
bool seen[N];
vector<pair<int,int> >team,chck;
int match[N], n, m, k, speed[N];
vi v[N];
ll dist[N][N];
bool bpm(int idx){
for(int to : v[idx]){
if(!seen[to]){
seen[to] = true;
if(match[to] == -1 || bpm(match[to])){
match[to] = idx;
return true;
}
}
}
return false;
}
bool check(ll _time){
int i, j;
for(i = 0; i < team.size(); i++){
v[i].clear();
for(j = 0; j < chck.size(); j++){
if(_time >= dist[i][j]){
v[i].pb(j);
}
}
}
for(i = 0; i < chck.size(); i++){
match[i] = -1;
seen[i] = false;
}
int match_ = 0;
for(int i = 0; i < team.size(); i++){
for(j = 0; j < chck.size(); j++){
seen[j] = false;
}
if(bpm(i)) match_++;
}
if(match_ >= k) return true;
return false;
}
ll solve(){
ll l = 0, r = 1ll * 1e16;
ll ans = 0;
while(l <= r){
ll mid = (l + r) / 2;
if(check(mid)){
ans = mid; r = mid - 1;
}else l = mid + 1;
}
return ans;
}
int main(){
cin >> n >> m >> k;
pair<int, int> tmp;
for(int i = 0; i < n; i++){
cin >> tmp.first >> tmp.second;
team.pb(tmp);
}
for(int i = 0; i < m; i++){
cin >> tmp.first >> tmp.second;
chck.pb(tmp);
}
for(int i = 0; i < n; i++) cin >> speed[i];
for(int i = 0; i < team.size(); i++){
for(int j=0;j<chck.size();j++){
ll val,tmp;
val=(chck[j].first-team[i].first);
val=val * val;
tmp=(chck[j].second-team[i].second);
tmp=tmp*tmp;
dist[i][j]=val+tmp;
if(dist[i][j]%speed[j])
dist[i][j]=(dist[i][j]/speed[i])+1;
else
dist[i][j]=dist[i][j]/speed[i];
}
}
cout<<solve()<<endl;
//fclose(stdout);
return 0;
}