forked from Sahaj-Bamba/HacktoberTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwat.cpp
More file actions
56 lines (53 loc) · 818 Bytes
/
wat.cpp
File metadata and controls
56 lines (53 loc) · 818 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
46
47
48
49
50
51
52
53
54
55
56
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define MIN(a,b) (a>b?b:a)
using namespace std;
ll func(ll);
ll t,n,ar[100005],low,high,mid,k,gap,mingap,ans;
int main()
{
cin>>t;
while(t--)
{
mingap=INF;
cin>>n;
rep(i,0,n)
cin>>ar[i];
low=0;
high=ar[n-1];
while(low<=high)
{
mid=(low+high)/2;
gap=INF;
if(func(mid)==1)
{
ans=mid;
mingap=gap;
low=mid+1;
}
else
high=mid-1;
}
if(n!=1)
cout<<ans<<" "<<mingap+1<<"\n";
else
cout<<ar[0]-1<<" "<<ar[0]<<"\n";
}
}
ll func(ll mid)
{
ll s=1;
rep(i,0,n)
{
if(ar[i]<s)
return 0;
if((ar[i]-s)<gap)
gap=ar[i]-s;
s+=mid;
}
return 1;
}