BOJ_S3_11047
π [S3_11047] λμ 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static StringTokenizer st;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
st = new StringTokenizer(br.readLine(), " ");
// λμ μ μ’
λ₯
int N = Integer.parseInt(st.nextToken());
// κ°μΉμ ν©
int K = Integer.parseInt(st.nextToken());
// λμ λ°°μ΄
int[] arr = new int[N];
// λμ κ°μμ μ΅μκ°
int res = 0;
// λμ μ
λ ₯ λ°κΈ°
for(int i=0; i<N; i++){
arr[i] = Integer.parseInt(br.readLine());
}
int idx = N-1;
while(K!=0){
// Kκ° λ°°μ΄μ μμλ³΄λ€ ν΄ κ²½μ° λΉΌμ€λ€
if(K>=arr[idx]){
while(K>=arr[idx]){
K -= arr[idx];
res++;
}
}
idx--;
}
sb.append(res);
System.out.println(res);
}
}
π€ λμ μκ°
κ°λ¨ν λ¬Έμ λ€..
λ°°μ΄ μ€μ Kλ³΄λ€ ν¬λ©΄ λΉΌμ£Όλ©΄μ κ·Έ λΉλλ₯Ό μΉ΄μ΄ν
ν΄μ£Όλ©΄ λλ€.
μ²μμλ λ€λ₯Έ 쑰건λ€μ΄ μλ μ€ μμλλ° μ무 κ²λ μμ΄μ κ°λ¨νκ² ν μ μμλ€.