10/08/2013

11559 - Event Planning - Java

 import java.io.BufferedReader;  
 import java.io.IOException;  
 import java.io.InputStream;  
 import java.io.InputStreamReader;  
 import java.util.StringTokenizer;  
 public class EventPlanning {  
      public static void main(String[] args) throws Exception {  
           BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));  
           int participants;  
           int budget;  
           int noOfHotels;  
           int noOfWeeks;  
           int bestCost;  
           String line;  
           while(true) {  
                boolean flag = false;  
                line = reader.readLine();  
                if(line == null || line.isEmpty()) break;  
                String[] vars = line.split(" ");  
                participants = Integer.parseInt(vars[0]);  
                budget = Integer.parseInt(vars[1]);  
                noOfHotels = Integer.parseInt(vars[2]);  
                noOfWeeks = Integer.parseInt(vars[3]);  
                int[] hotelCost = new int[noOfHotels];  
                bestCost = Integer.MAX_VALUE;  
                for(int i = 0; i < noOfHotels; i++) {  
                     hotelCost[i] = Integer.parseInt(reader.readLine());  
                     boolean validHotel = false;  
                     line = reader.readLine();  
                     String[] rooms = line.split(" ");  
                     for(int j = 0; j < noOfWeeks; j++) {  
                          if(Integer.parseInt(rooms[j]) >= participants) {  
                               validHotel = true;  
                          }  
                          if(validHotel) {  
                               if(bestCost > hotelCost[i]) bestCost = hotelCost[i];  
                               flag = true;  
                          }  
                     }  
                }  
                if(flag) {  
                     int sum = bestCost * participants;  
                     if(sum <= budget) System.out.println(bestCost * participants);  
                     else System.out.println("stay home");  
                }  
                else System.out.println("stay home");  
           }  
      }  
 }  

1 comment:

  1. Thank you for sharing such a valuable post on events. It will be an advantage to hire Event Organizer for your products or services.

    ReplyDelete