UVa 11559 – Event Planning


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class UVa11559_eventPlanning {

	static int n,b,h,w;
	static int[] costs ;
	static int [][] hotels ;

	static int solve(){
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (hotels[i][j]>=n && costs[i]*n <=b){
					min = min>costs[i]*n ?costs[i]*n : min ;
				}
			}
		}

		return min ;
	}

	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tk ;
		String s ;
		while(true){
			s= br.readLine();
			if(s==null || s.isEmpty())System.exit(0);
			tk = new StringTokenizer(s);
			n = Integer.parseInt(tk.nextToken());
			b = Integer.parseInt(tk.nextToken());
			h = Integer.parseInt(tk.nextToken());
			w = Integer.parseInt(tk.nextToken());
			costs = new int[h];
			hotels = new int [h][w];

			for (int i = 0; i < h; i++) {
				costs[i] = Integer.parseInt(br.readLine());
				tk = new StringTokenizer(br.readLine());
				for (int j = 0; j < w; j++) {
					hotels[i][j] = Integer.parseInt(tk.nextToken());
				}
			}
			int res = solve();
			if (res == Integer.MAX_VALUE)
			System.out.println("stay home");
			else System.out.println(res);

		}
	}

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s