Usaco Jan08 Bronze

Part of USACO Jan08

**********************************************************************
                           BRONZE PROBLEMS
**********************************************************************
                  Three problems numbered 11 through 13
**********************************************************************

Problem 11: Costume Party [Neal Wu, 2007]

It's Halloween! Farmer John is taking the cows to a costume party,
but unfortunately he only has one costume. The costume fits precisely
two cows with a length of S (1 <= S <= 1,000,000). FJ has N cows
(2 <= N <= 20,000) conveniently numbered 1..N; cow i has length L_i
(1 <= L_i <= 1,000,000). Two cows can fit into the costume if the
sum of their lengths is no greater than the length of the costume.
FJ wants to know how many pairs of two distinct cows will fit into
the costume.

PROBLEM NAME: costume

INPUT FORMAT:

* Line 1: Two space-separated integers: N and S

* Lines 2..N+1: Line i+1 contains a single integer: L_i

SAMPLE INPUT (file costume.in):

4 6
3
5
2
1

OUTPUT FORMAT:

* Line 1: A single integer representing the number of pairs of cows FJ
        can choose. Note that the order of the two cows does not
        matter.

SAMPLE OUTPUT (file costume.out):

4

OUTPUT DETAILS:

The four pairs are as follows: cow 1 and cow 3; cow 1 and cow 4; cow 2 and
cow 4; and finally cow 3 and cow 4.

**********************************************************************

Problem 12: Election Time [Jeffrey Wang, 2007]

The cows are having their first election after overthrowing the
tyrannical Farmer John, and Bessie is one of N cows (1 <= N <=
50,000) running for President. Before the election actually happens,
however, Bessie wants to determine who has the best chance of
winning.

The election consists of two rounds. In the first round, the K cows
(1 <= K <= N) cows with the most votes advance to the second round.
In the second round, the cow with the most votes becomes President.

Given that cow i expects to get A_i votes (1 <= A_i <= 1,000,000,000)
in the first round and B_i votes (1 <= B_i <= 1,000,000,000) in the
second round (if he or she makes it), determine which cow is expected
to win the election. Happily for you, no vote count appears twice
in the A_i list; likewise, no vote count appears twice in the B_i
list.

PROBLEM NAME: elect

INPUT FORMAT:

* Line 1: Two space-separated integers: N and K

* Lines 2..N+1: Line i+1 contains two space-separated integers: A_i
        and B_i

SAMPLE INPUT (file elect.in):

5 3
3 10
9 2
5 6
8 4
6 5

INPUT DETAILS:

There are 5 cows, 3 of which will advance to the second round. The cows
expect to get 3, 9, 5, 8, and 6 votes, respectively, in the first round and
10, 2, 6, 4, and 5 votes, respectively, in the second.

OUTPUT FORMAT:

* Line 1: The index of the cow that is expected to win the election.

SAMPLE OUTPUT (file elect.out):

5

OUTPUT DETAILS:

Cows 2, 4, and 5 advance to the second round; cow 5 gets 5 votes in the
second round, winning the election.

**********************************************************************

Problem 13: iCow [Jeffrey Wang, 2008]

Fatigued by the endless toils of farming, Farmer John has decided
to try his hand in the MP3 player market with the new iCow. It is
an MP3 player that stores N songs (1 <= N <= 1,000) indexed 1 through
N that plays songs in a "shuffled" order, as determined by Farmer
John's own algorithm:

   * Each song i has an initial rating R_i (1 <= R_i <= 10,000).

   * The next song to be played is always the one with
     the highest rating (or, if two or more are tied, the highest
     rated song with the lowest index is chosen).

   * After being played, a song's rating is set to zero, and its rating
     points are distributed evenly among the other N-1 songs.

   * If the rating points cannot be distributed evenly (i.e.,
     they are not divisible by N-1), then the extra points are
     parceled out one at a time to the first songs on the list
     (i.e., R_1, R_2, etc. -- but not the played song) until no
     more extra points remain.

This process is repeated with the new ratings after the next song
is played.

Determine the first T songs (1 <= T <= 1000) that are played by the
iCow.

PROBLEM NAME: icow

INPUT FORMAT:

* Line 1: Two space-separated integers: N and T

* Lines 2..N+1: Line i+1 contains a single integer: R_i

SAMPLE INPUT (file icow.in):

3 4
10
8
11

INPUT DETAILS:

The iCow contains 3 songs, with ratings 10, 8, and 11, respectively.
You must determine the first 4 songs to be played.

OUTPUT FORMAT:

* Lines 1..T: Line i contains a single integer that is the i-th song
        that the iCow plays.

SAMPLE OUTPUT (file icow.out):

3
1
2
3

OUTPUT DETAILS:

The ratings before each song played are:
   R_1  R_2  R_3
    10    8   11  -> play #3  11/2 = 5, leftover = 1
    16   13    0  -> play #1  16/2 = 8
     0   21    8  -> play #2  21/2 = 10, leftover = 1
    11    0   18  -> play #3  ...

**********************************************************************
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License