typedef unsigned long ul;
typedef unsigned long long ull;
int main()
{
int t, n;
ull k, *a;
std::cin >> t;
while(t--)
{
std::cin >> n >> k;
a = new ull[n];
for(int i = 0; i < n; i++)
{
std::cin >> a[i];
}
int max_index = 1;
ull n1, n2;
n1 = pow(k, a[0]);
n2 = pow(k, a[1]);
for(int i = 2; i < n; i++)
{
n2 += pow(k, a[i]);
}
ull max_product = n1 * n2;
for(int i = 1; i < n - 1; i++)
{
ull x = pow(k, a[i]);
n1 += x;
n2 -= x;
ull product = n1 * n2;
if(product > max_product)
{
max_product = product;
max_index = i + 1;
}
}
delete[] a;
std::cout << max_index << "\n";
}
return 0;
}
It only passes one test case
I think its because even unsigned long long cannot store such huge values
Or is it the algorithm?