๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[๋ฐฑ์ค€] 10409๋ฒˆ: ์„œ๋ฒ„

by ์ฃผ๋ฐœ2 2020. 5. 20.
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/10409

 

10409๋ฒˆ: ์„œ๋ฒ„

๋ฌธ์ œ ๋‹น์‹ ์€ FCFS(First-Come, First-Served)์˜ ๊ทœ์น™์— ๋”ฐ๋ผ ์š”์ฒญ๋œ ์ผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์„œ๋ฒ„๋ฅผ ๋‹ด๋‹นํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ๋งค์ผ, ๋‹น์‹ ์€ ์ผ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์ตœ๋Œ€ T๋ถ„ ๋™์•ˆ ์„œ๋ฒ„์— ์‹œ๊ฐ„์„ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹น์‹ ์€ ์˜ค๋Š˜ ๏ฟฝ

www.acmicpc.net

์ฝ”๋“œ

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(bf.readLine());
		int n = Integer.parseInt(st.nextToken());	// ์ผ์˜ ๊ฐœ์ˆ˜
		int T = Integer.parseInt(st.nextToken());	// ์ด ์‹œ๊ฐ„
		int count = 0;	// ์™„๋ฃŒํ•  ์ˆ˜ ์žˆ๋Š” ์ผ์˜๊ฐœ์ˆ˜
		int sum = 0;	// ์ผ์˜ ์‹œ๊ฐ„ ํ•ฉ
		
		st = new StringTokenizer(bf.readLine());
		int[] arr = new int[n];
		for(int i=0; i<arr.length; i++)
			arr[i] = Integer.parseInt(st.nextToken());
		
		for(int i=0; i<arr.length; i++) {
			sum += arr[i];
			
			if(sum > T)	// ์ฃผ์–ด์ง„ ์‹œ๊ฐ„๋ณด๋‹ค ์ˆ˜ํ–‰ํ•œ ์ผ์˜ ์‹œ๊ฐ„์ด ๋” ํด๊ฒฝ์šฐ -> ์ผ ์ค‘์ง€
				break;
			
			count ++;
		}
		
		System.out.println(count);
		bf.close();
	}

}

ํ’€์ด

์ฃผ์–ด์ง„ ์ผ์˜ ์‹œ๊ฐ„๋“ค์„ ๋”ํ•˜๋ฉด์„œ, ์ฃผ์–ด์ง„ ์‹œ๊ฐ„๋ณด๋‹ค ํด๊ฒฝ์šฐ, for๋ฌธ์„ ๋น ์ ธ๋‚˜๊ฐ€๋ฉด ๋.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€