Skip to content

Commit

Permalink
백준 7579번 앱 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
skysign committed Feb 9, 2025
1 parent 71acafb commit 12f193b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 백준 7579번 앱 v2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys


def solve():
input = sys.stdin.readline
N, M = map(int, input().strip().split())
mems = [0] + list(map(int, input().strip().split()))
costs = [0] + list(map(int, input().strip().split()))
costs_sum = sum(costs)
dp = [[0 for _ in range(costs_sum + 1)] for _ in range(N + 1)]
answer = 100 * 100

for idx_app in range(1, N + 1):
for cost_crnt in range(0, costs_sum + 1):
if cost_crnt < costs[idx_app]:
dp[idx_app][cost_crnt] = dp[idx_app - 1][cost_crnt]
else:
dp[idx_app][cost_crnt] = max(dp[idx_app - 1][cost_crnt], dp[idx_app -1][cost_crnt - costs[idx_app]] + mems[idx_app])

if dp[idx_app][cost_crnt] >= M:
answer = min(answer, cost_crnt)

print(answer)


if __name__ == '__main__':
solve()
3 changes: 3 additions & 0 deletions 백준 7579번 앱 v2/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
5 60
30 10 20 35 40
3 0 3 5 4
1 change: 1 addition & 0 deletions 백준 7579번 앱 v2/test1_answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
23 changes: 23 additions & 0 deletions 백준 7579번 앱 v2/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
from pathlib import Path
from unittest import TestCase
from main import solve


class Test(TestCase):
def my_solve(self, testcase_input):
sys.stdin = open(testcase_input, 'r')
stdout = sys.stdout
sys.stdout = open('stdout.txt', 'w')
solve()
sys.stdout.close()
sys.stdout = stdout

def test_solve(self, testcase_number: str):
self.my_solve('test' + testcase_number + '.txt')
self.assertEqual(
Path('test' + testcase_number + '_answer.txt').read_text().strip(),
Path('stdout.txt').read_text().strip())

def test1_solve(self):
self.test_solve('1')

0 comments on commit 12f193b

Please sign in to comment.