Skip to content

Commit 3aa7f6d

Browse files
Add files via upload
1 parent f653d59 commit 3aa7f6d

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
void solve()
7+
{
8+
int no_of_elements;
9+
cin >> no_of_elements;
10+
11+
vector <int> A(no_of_elements + 1);
12+
for(int i = 1; i <= no_of_elements; i++)
13+
{
14+
cin >> A[i];
15+
}
16+
17+
int minimum = 1, maximum = 1;
18+
for(int i = 1; i <= no_of_elements; i++)
19+
{
20+
if(A[i] >= A[maximum])
21+
{
22+
maximum = i;
23+
}
24+
else if(A[i] < A[minimum])
25+
{
26+
minimum = i;
27+
}
28+
}
29+
30+
cout << minimum << " " << maximum << "\n";
31+
}
32+
33+
int main()
34+
{
35+
int no_of_test_cases;
36+
cin >> no_of_test_cases;
37+
38+
while(no_of_test_cases--)
39+
solve();
40+
41+
return 0;
42+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
long long get_odd_part(long long n)
8+
{
9+
while(n%2 == 0)
10+
{
11+
n = n >> 1;
12+
}
13+
14+
return n;
15+
}
16+
17+
void solve()
18+
{
19+
long long n;
20+
cin >> n;
21+
22+
if(n%2 == 1)
23+
{
24+
cout << "2\n";
25+
return;
26+
}
27+
28+
long long original_n = n;
29+
long long odd_part = 1, even_part = 1;
30+
while(n%2 != 1)
31+
{
32+
n = n >> 1;
33+
34+
even_part *= 2;
35+
}
36+
odd_part = n;
37+
//cout << "E = " << even_part << " O = " << odd_part << "\n";
38+
39+
if(odd_part == 1)
40+
{
41+
cout << "-1\n";
42+
return;
43+
}
44+
45+
cout << min(2*even_part, odd_part) << "\n";
46+
}
47+
48+
int main()
49+
{
50+
int no_of_test_cases;
51+
cin >> no_of_test_cases;
52+
53+
while(no_of_test_cases--)
54+
solve();
55+
56+
return 0;
57+
}
58+
59+
60+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <map>
4+
5+
using namespace std;
6+
7+
void solve()
8+
{
9+
int no_of_elements, k;
10+
cin >> no_of_elements >> k;
11+
12+
vector <long long> A(no_of_elements + 1);
13+
for(int i = 1; i <= no_of_elements; i++)
14+
{
15+
cin >> A[i];
16+
}
17+
18+
map <int, int> present;
19+
for(int i = 1; i <= no_of_elements; i++)
20+
{
21+
present[A[i]] = true;
22+
}
23+
24+
int possible = false;
25+
for(int i = 1; i <= no_of_elements; i++)
26+
{
27+
if(present[A[i] - k] || present[A[i] + k])
28+
{
29+
possible = true;
30+
break;
31+
}
32+
}
33+
34+
cout << (possible ? "Yes" : "No") << "\n";
35+
}
36+
37+
int main()
38+
{
39+
int no_of_test_cases;
40+
cin >> no_of_test_cases;
41+
42+
while(no_of_test_cases--)
43+
solve();
44+
45+
return 0;
46+
}
47+

0 commit comments

Comments
 (0)