function CitySavers(N,Monsters,Savers) {
	var cur,pre = 0,total = 0;
	for(let i=0;i<=N;i++){
		if(Savers[i]){
			cur = Savers[i] + pre;
		}else{
			cur = pre;
		}
		if(cur > Monsters[i]){
			pre = cur - Monsters[i];
			total += Monsters[i];
		}else{
			total += cur; 
		}
	}
	console.log(total);
}

