[자바JAVA]Luck Balance 해커랭크
문제 : Luck Balance
contests에서 각 대회가 중요하면 1이고 중요하지 않으면 0이다.
k는 중요한 대회에서 질 수 있는 횟수이다.
contests에서 지면 행운이 높아지고 이기면 행운이 낮아진다.
최대 행운이 얼마인지 구하는 문제이다.
Lena is preparing for an important coding competition that is preceded by a number of sequential preliminary contests. Initially, her luck balance is 0. She believes in “saving luck”, and wants to check her theory. Each contest is described by two integers, L[i] and T[i]:
L[i] is the amount of luck associated with a contest. If Lena wins the contest, her luck balance will decrease by L[i]; if she loses it, her luck balance will increase by L[i].
T[i] denotes the contest’s importance rating. It’s equal to 1 if the contest is important, and it’s equal to 0 if it’s unimportant.
If Lena loses no more than K important contests, what is the maximum amount of luck she can have after competing in all the preliminary contests? This value may be negative.입출력예시
1 | //입력 |
코드
1 | static int luckBalance(int k, int[][] contests) { |