Source Code
#include<iostream>
using namespace std;

int main() {
	int counter = 0;
	int n, k;
	int *h=new int[100001];
	cin >> n>>k;
	for (int i = 0;i < n;i++)
		cin >> h[i];
	int multi = 1;
	int flag = 1;
	int i = 0;
	while(1) {
		if (k >= multi * (h[i]) && flag == 1) {
			k = k - multi * h[i];
			counter++;
			i++;
			if (i == n)
			{
				flag = 0;
				i--;
				multi++;
			}

		}

		else if (k >= multi * h[i] && flag == 0) {
			k = k - multi * h[i];
			counter++;
			i--;
			if (i < 0) {
				flag = 1;
				multi++;
				i++;
			}

		}
		else break;
		
	}
	cout << counter;


}
Copy
Saqqa 26/40 hoodlum awm
GNU G++17
2076 ms
936 KB
Time Limit Exceeded