answersLogoWhite

0


Best Answer

/*

ID: isurube1

LANG: JAVA

TASK: gift1

*/

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

public class gift1 {

public static void main(String[] args) {

try{

BufferedReader fileIn = new BufferedReader(new FileReader("gift1.in"));

PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter("gift1.out")));

try{

int quantity = Integer.parseInt(fileIn.readLine());

String[][] outFile = new String [quantity][2];

for (int i = 0; i < quantity; i++) {

outFile [i][0] = fileIn.readLine();

outFile [i][1] = "0";

}

for (int i = 1; i <= quantity; i++) {

String giver = fileIn.readLine();

String temp = fileIn.readLine();

int money = Integer.parseInt(temp.split(" ")[0]);

int receivers = Integer.parseInt(temp.split(" ")[1]);

int giversValue = 0;

if (money != 0 receivers != 0){

giversValue = (money % receivers) - money;

}

for (int j = 0; j < outFile.length; j++) {

if (outFile[j][0].equals(giver)){

outFile[j][1] = Integer.toString(giversValue + Integer.parseInt(outFile[j][1]));

break;

}

}

if(receivers != 0){

money /= receivers;

for (int j = 1; j <= receivers; j++) {

temp = fileIn.readLine();

for (int k = 0; k < outFile.length; k++) {

if (outFile[k][0].equals(temp)){

outFile[k][1] = Integer.toString(money + Integer.parseInt(outFile[k][1]));

break;

}

}

}

}

}

for (int i = 0; i < outFile.length; i++) {

fileOut.write(outFile[i][0] + " " +outFile[i][1]+"\n");

}

} finally {

fileIn.close();

fileOut.close();

}

} catch (IOException e) {

throw new RuntimeException(e);

}

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you solve Usaco Greedy Gift Givers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are Spain gift giver?

What are the Spain gifts givers


In the giver what is the givers extra gift?

The memory of music.


What are the release dates for The Gift of All A Community of Givers - 2008?

The Gift of All A Community of Givers - 2008 was released on: USA: 8 November 2008 (Grand Rapids, Michigan)


By what title were the the three wise men known?

as the gift givers to jesus


When was The Gift That Keeps Giving created?

The Gift That Keeps Giving was created on 2007-12-25.


Does Kwanzaa have any gift givers?

well, during Kwanzaa, the adults/elders give gifts to the children.


Why do your stores not accept Subway gift cards?

The Black Ones. Their Greedy!


Who is the gift bringer in Brazil?

There are two gift givers in Brazil for Christmas. One is Papai Noel who is Father Christmas. The other is Bom Velhinho who is the Good Old Man.


Are Della and Jim the wisest gift givers?

Yes, Della and Jim are wise gift givers because they both sacrificed their most treasured possessions to purchase gifts for each other that held great sentimental value and symbolized their love and appreciation. Their gifts were thoughtful and selfless, embodying the true spirit of giving.


Father's Day Gift Baskets: Perfect for Dad and Your Budget ?

Gift baskets make great gifts because a number of items are combined in an attractive package. Creating homemade Father's Day gift baskets allows gift givers to personalize gifts for dads, grandparents or other recipients. These gifts can also be created in ways that suit gift givers' budgets. Gathering a number of small items to fill baskets can be less expensive than splurging on one large item. Purchasing items over time allows gift givers to take advantage of sales and discounts and allows givers to spend small amounts over time rather than large lump sums. Father's Day gift baskets can be created by using a basket or other container to hold several small items. Selecting a theme for the gifts to be included in the basket makes the gift basket into one cohesive gift. Some popular themes are movie night, sports or foods. Personalizing Father's Day gift baskets for their recipients by filling baskets with items related to their favorite things or activities creates gifts that let the recipients know they are truly appreciated. Gift baskets can give big without requiring givers to spend big.


What is the gift giver if Bethlehem called?

The gift givers in Betlehem were known as Magi, they were the star gazers of the time; Astrologists, Alchemists, perhaps, etc. They were not kings and there were probably more than three.


What are the release dates for Steve Harvey - 2012 Steve Helps Husbands Who Are the Worst Gift-Givers Tasty Traditions Awkward Holiday Photos 2-67?

Steve Harvey - 2012 Steve Helps Husbands Who Are the Worst Gift-Givers Tasty Traditions Awkward Holiday Photos 2-67 was released on: USA: 18 December 2013