Dev.baelanche

[백준 10409] 서버 본문

Data Structure & Algorithm/PS - JAVA

[백준 10409] 서버

baelanche 2019. 4. 12. 21:16
반응형

 

 

1. 일의 시간 정보를 배열에 담는다.

2. 일이 들어온 순서대로만 처리하므로 배열의 앞 인덱스부터 수행 시간을 비교하여 푼다.

 

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a[] = new int[n];
        int cnt = 0;
        
        for(int i=0; i<n; i++)
            a[i] = sc.nextInt();
        
        for(int i=0; i<n; i++) {
            t -= a[i];
            if(t < 0) break;
            cnt++;
        }
        System.out.println(cnt);
        sc.close();
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 2909] 캔디 구매  (0) 2019.04.12
[백준 1260] DFS와 BFS  (0) 2019.04.12
[백준 2804] 크로스워드 만들기  (0) 2019.04.12
[백준 5533] 유니크  (0) 2019.04.12
[백준 5212] 지구 온난화  (0) 2019.04.11
Comments