-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Lucky_Numbers.cpp
More file actions
65 lines (62 loc) · 1.19 KB
/
A_Lucky_Numbers.cpp
File metadata and controls
65 lines (62 loc) · 1.19 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
// Jai shree ram
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int n = 1e6 + 10;
int ar[n];
void Haribol()
{
int a, b;
cin >> a >> b;
int ans = 0;
int ans2 = 0;
int ct;
if (b != a)
ct = b - a + 1;
else
ct = b - a;
int temp = a;
for (int i = 0; i <= 10000 and temp <= b; i++)
{
if (ar[a + i] >= ans2)
{
ans2 = ar[a + i];
ans = a + i;
}
temp++;
}
ans2 = 0;
int ans3 = 0;
temp = b;
for (int i = 0; i <= 10000 and temp >= a; i++)
{
if (ar[b - i] >= ans2)
{
ans2 = ar[b - i];
ans3 = b - i;
}
temp--;
}
cout << max(ans,ans3) << '\n';
return;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for (int i = 0; i < 10; i++)
{
ar[i] = 0;
}
for (int i = 10; i < n; i++)
{
string s = to_string(i);
ar[i] = (*(max_element(s.begin(), s.end()))) - (*(min_element(s.begin(), s.end())));
}
int t;
cin >> t;
while (t--)
{
Haribol();
}
}