-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBowling Frame
69 lines (58 loc) · 1.13 KB
/
Bowling Frame
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
#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma G++ optimize(2)
#pragma G++ optimize(3)
const int MOD=1e9+7;
const int N=1000100;
__int128 read()
{
int x=0,w=1;
char ch=getchar();
while(!isdigit(ch)){ w|=(ch=='-'); ch=getchar(); }
while(isdigit(ch)) { x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*w;
}
void write(__int128 x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
int a[N];
int b[N];
int pre[N];
void solve() {
int num1,num2;
cin>>num1>>num2;
int l=0,r=num1+num2;
while(l<r) {
int mid = (l+r+1)>>1;
int now = mid;
int n1=num1,n2=num2;
int ans=0;
while(now>0) {
if(n1 > n2) swap(n1,n2);
if(n1>=now) n1-=now,now--,ans++;
else if(n2>=now) n2-=now,now--,ans++;
else break;
}
if(now>0) r=mid-1;
else l=mid;
}
cout<<l<<"\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}