Skip to content

Commit

Permalink
백준 7579번 앱
Browse files Browse the repository at this point in the history
  • Loading branch information
skysign committed Nov 3, 2024
1 parent 29668e2 commit 9248e5b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 백준 7579번 앱/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys


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

for idx_app in range(1, N + 1):
for cost_crnt in range(cost_max + 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 - costs[idx_app]] + memeories[idx_app], dp[idx_app - 1][cost_crnt])

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번 앱/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번 앱/test1_answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
23 changes: 23 additions & 0 deletions 백준 7579번 앱/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 9248e5b

Please sign in to comment.