이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.*;
public class bank {
public static void main (String[]args) {
Scanner scan = new Scanner (System.in);
int peopleNumber = scan.nextInt();
int bankNoteNumber = scan.nextInt();
int [] salaries = new int [peopleNumber];
for (int i = 0; i < peopleNumber; i++) {
salaries[i] = scan.nextInt();
}
int [] bankNotes = new int [bankNoteNumber];
for (int i = 0; i < bankNoteNumber; i++) {
bankNotes[i] = scan.nextInt();
}
int subsetNumber = (int)Math.pow(2, bankNoteNumber);
int [] maxPrefix = new int [subsetNumber];
int [] leftOver = new int [subsetNumber];
Arrays.fill(maxPrefix, Integer.MIN_VALUE);
Arrays.fill(leftOver, Integer.MIN_VALUE);
maxPrefix[0] = 0;
leftOver[0] = 0;
int max = 0;
for (int i = 0; i < subsetNumber; i++) {
int peopleFinished = maxPrefix[i];
max = Math.max(max, peopleFinished);
if (max == peopleNumber) {
break;
}
if (peopleFinished == Integer.MIN_VALUE) {
continue;
}
for (int j = 0; j < bankNoteNumber; j++) {
// Checking if the current bank note has been unused
if ((i & (1 << j)) == 0) {
int currentPersonTarget = salaries[peopleFinished];
int currentBankNote = bankNotes[j];
int currentLeftOver = leftOver[i];
int newIndex = i + (int)Math.pow(2, j);
if (currentLeftOver + currentBankNote < currentPersonTarget) {
maxPrefix[newIndex] = maxPrefix[i];
leftOver[newIndex] = currentLeftOver + currentBankNote;
}
if (currentLeftOver + currentBankNote == currentPersonTarget) {
maxPrefix[newIndex] = maxPrefix[i] + 1;
leftOver[newIndex] = 0;
}
}
}
}
if (max == peopleNumber) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |