Source Code
#include <iostream>
using namespace std;
int main()
{
	long long n, k;
	cin >> n >> k;
	int* initial = new int[n];
	unsigned long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> initial[i];
		sum += initial[i];
	}

	int i = 0;
	int increment = 1;
	int climbed = 0;
	int factor = 1;
	while (k >= sum)
	{
		climbed += n;
		k -= sum;
		factor++;
		sum *= factor;
		increment *= -1;
	}
	if (increment == -1)
		i = n - 1;
	while (k >= factor * initial[i])
	{
		k -= (factor * initial[i]);
		climbed++;
		i += increment;
		if (i == n)
		{
			i--;
			increment = -1;
			factor++;
		}
		else if (i == -1)
		{
			i++;
			increment = 1;
			factor++;
		}
	}
	cout << climbed;
	delete[] initial;
}
Copy
Saqqa 26/40 Heromnxpw0
GNU G++17
3 ms
620 KB
Wrong Answer