Source Code
#include <iostream>
using namespace std;

int main() {
	
	int n;
	unsigned long long k;
	cin>>n>>k;
	int arr[n];
	int basearr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
		basearr[i]=arr[i];
	}
	int walls=0;
	bool hecan=true;
	while(hecan){
		for(int i=0; i<n; i++){
			if(k>=arr[i]){
				k-=arr[i];
				arr[i]+=basearr[i];
				walls++;
			}
			else {
				hecan=false;
				break;
			}
		}
		if(!hecan)break;
		else{
			for(int i=n-1; i>=0; i--){
				if(k>=arr[i]){
					k-=arr[i];
					arr[i]+=basearr[i];
					walls++;
				}
				else{
					hecan=false;
					break;
				}
			}
		}
	}
	cout<<walls;
	return 0;
}
Copy
Saqqa 26/40 samihamad
GNU G++17
2071 ms
1.7 MB
Time Limit Exceeded