Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[BAEKJOON] 7579. 앱 본문

acmicpc

[BAEKJOON] 7579. 앱

코드와이 2021. 4. 19. 23:17

 

배낭문제

문제링크

www.acmicpc.net/problem/7579

 

7579번: 앱

입력은 3줄로 이루어져 있다. 첫 줄에는 정수 N과 M이 공백문자로 구분되어 주어지며, 둘째 줄과 셋째 줄에는 각각 N개의 정수가 공백문자로 구분되어 주어진다. 둘째 줄의 N개의 정수는 현재 활

www.acmicpc.net

 

package acmicpc.Gold3;

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

public class 앱 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		
		int[] arr1 = new int[n];
		int[] arr2 = new int[n];
		
		st = new StringTokenizer(br.readLine());
		for(int i = 0 ; i < n ; i++) {
			arr1[i] = Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(br.readLine());
		for(int i = 0 ; i < n ; i++) {
			arr2[i] = Integer.parseInt(st.nextToken());
		}

		int[][] dp = new int[n][100001];
		int ans = 9876421;
		
		for(int i = 0 ; i < n ; i++) {
			int memory = arr1[i];
			int cost = arr2[i];
			
			for(int j = 0 ; j < 100001 ; j++) {
				if(i == 0) {
					if(j >= cost) dp[i][j] = memory;
				} else {
					if(j >= cost) dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j - cost] + memory);
					else dp[i][j] = dp[i-1][j];
				}
				if(m <= dp[i][j]) ans = Math.min(ans, j);
			}
		}
		
		System.out.println(ans);
	}
}

'acmicpc' 카테고리의 다른 글

[BAEKJOON] 15683. 감시  (0) 2021.04.21
[BAEKJOON] 16985. Maaaaaaaaaze  (0) 2021.04.21
[BAEKJOON] 1516. 게임 개발  (0) 2021.04.19
[BAEKJOON] 2056. 작업  (0) 2021.04.19
[BAEKJOON] 2637. 장난감조립  (0) 2021.04.19