-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA to B
56 lines (45 loc) Β· 1.19 KB
/
A to B
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define fr(i, n) for (ll i = 0; i < n; i++)
#define pb push_back
#define sze(x) x.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#pragma GCC optimize("unroll-loops,O3,Ofast")
#pragma GCC target("avx2,avx,fma,bmi,bmi2,lzcnt,popcnt")
#define ff first
#define ss second
#define py cout << "YES\n"
#define pn cout << "NO\n"
#define mk minavkaria
int main() {
// your code goes here
int t;
cin >> t;
while (t--)
{
int x1,y1,z1,x2,y2,z2,k;
cin>>x1>>y1>>z1>>x2>>y2>>z2>>k;
int distX=abs(x1-x2);
int distY=abs(y1-y2);
int distZ=abs(z1-z2);
vector<int> a={distX,distY,distZ};
sort(rall(a));
int gap=((a[0]+k-1)/k)-1;
// cout<<gap<<"--\n";
if(a[1]+a[2]>=gap)
{
// cout<<"I am here";
cout<<distX+distY+distZ<<"\n";
}
else
{
int ext=gap-(a[1]+a[2]);
cout<<distX+distY+distZ+ext+ext%2<<"\n";
}
}
return 0;
}