UVa : 10925 (Krakovia)



// http://uva.onlinejudge.org/external/109/10925.html
// Runtime : 0.744s
// Tag : BigInteger 

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class BigDecimalClass {

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int f = input.nextInt();
		int cases = 0;
		
		while ( n != 0 || f != 0 ) {
			BigInteger sum = BigInteger.ZERO;
			
			for ( int i = 0; i < n; i++ ) {
				BigInteger cost = input.nextBigInteger();
				sum = sum.add(cost);
			}
			//Bill #1 costs 16200000000: each friend should pay 5400000000
			System.out.printf("Bill #%d costs ", ++cases);
			System.out.print(sum + ": each friend should pay " + sum.divide(BigInteger.valueOf(f)) + "\n\n");
			
			n = input.nextInt();
			f = input.nextInt();
		}
	}
}
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