MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Dominant Piranha/solution.cpp:15–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13using namespace std;
14
15int main()
16{
17 ios_base::sync_with_stdio(false);
18 cin.tie(NULL);
19 int t;
20 cin >> t;
21 while (t--)
22 {
23 int n;
24 cin >> n;
25 int a[n];
26 int maxi = INT_MIN;
27 for (int i = 0; i < n; i++)
28 {
29 cin >> a[i];
30 if (maxi < a[i])
31 {
32 maxi = a[i];
33 }
34 }
35 bool status = true;
36 int i = 0;
37 while (i < n - 1)
38 {
39 if (a[i] != a[i + 1])
40 {
41 status = false;
42 break;
43 }
44 i++;
45 }
46 if (status)
47 {
48 cout << -1 << endl;
49 }
50 else
51 {
52 int i = 0;
53 bool status = true;
54 while (i < n && status)
55 {
56 if (a[i] == maxi)
57 {
58 if (i > 0 && a[i] != a[i - 1])
59 {
60 status = false;
61 }
62 if (i < n - 1 && a[i] != a[i + 1])
63 {
64 status = false;
65 }
66 }
67 i++;
68 }
69 cout << i << endl;
70 }
71 }
72 return 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected