-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_Array_32.cpp
More file actions
57 lines (57 loc) · 1.6 KB
/
Copy path04_Array_32.cpp
File metadata and controls
57 lines (57 loc) · 1.6 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
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,now,dest;
cin >> n;
int arr[n+1][3];
for(int i=0;i<n;i++){
int liftnum;
cin >> liftnum >> now >> dest;
arr[liftnum][0]=now;
arr[liftnum][1]=dest;
}
cin >> m;
int pnow, pdest, pickup=0, dropoff=0, total;
for(int i=0;i<m;i++){
cin >> pnow >> pdest;
for(int j=1;j<=n;j++){
now=arr[j][0];
dest=arr[j][1];
if(pnow>=dest && pnow<=now || pnow<=dest & pnow>=now){
pickup=0;
if(pdest>=dest){
dropoff=pdest-dest;
}
if(dest>=pdest){
dropoff=dest-pdest;
}
total = pickup+dropoff;
}else{
if(dest>=pnow){
pickup=dest-pnow;
}
if(pnow>=dest){
pickup=pnow-dest;
}
if(pnow>=pdest){
dropoff=pnow-pdest;
}
if(pdest>=pnow){
dropoff=pdest-pnow;
}
total = pickup+dropoff;
}
arr[j][2]=total;
// cout << "lift " << j << " pickup : " << pickup << " dropoff : " << dropoff <<" total : " << total << endl;
}
int mintravel=INT_MAX, bestlift;
for(int j=1;j<=n;j++){
if(arr[j][2]<mintravel){
mintravel=arr[j][2];
bestlift=j;
}
}
cout << ">> " << bestlift << endl;
}
return 0;
}