11559 - Event Planning

Problem Link

import java.util.*;

public class uva11559 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
int part, bgt, htl, w;
while(scn.hasNextInt()) {
part = scn.nextInt();
bgt = scn.nextInt();
htl = scn.nextInt();
w = scn.nextInt();
int min = 500000;
int b = 0;
int stay = 0;

for(int x=0;x<htl;x++) {
int bph = scn.nextInt(); // input budget per hotel
for(int y = 0; y < w; y++) {
int wb = scn.nextInt(); // input bed per week
if(wb >= part) { // bed per week more than or equal to participant
b = part * bph; // participant multiply by budget per hotel
if(b <= bgt) {// if b less than minimum budget
if(b <= min) {
min = b;
stay = 1;
}
}
}
else {
if(stay == 1)
stay = 1;
else if (stay == 0)
stay = 0;

}
}

}
if(stay > 0)
System.out.println(min);
else
System.out.println("stay home");
}
}
}

Share this

Related Posts

Previous
Next Post »