Connection Status:
Competition Arena > WinterAndPresents
SRM 601 · 2013-06-25 · by Witaliy · Brute Force
Class Name: WinterAndPresents
Return Type: long
Method Name: getNumber
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

It's winter time! You need to prepare a Christmas gift for your friend.

You have several bags arranged in a row. The bags only contain apples and oranges. You are given an int[] apple and an int[] orange. For each i, the i-th element of apple represents the number of apples in the i-th bag, and the i-th element of orange represents the number of oranges in the i-th bag.

You will choose the gift using the following procedure: First, you will choose any positive integer X such that there are at least X pieces of fruit in each bag. Then, you will take exactly X pieces of fruit out of each bag, and combine all the fruit into one present. Return the number of different gifts that may be produced by following the given procedure. (Two gifts are considered different if they contain a different number of apples or a different number of oranges.)

Constraints

  • apple will contain between 1 and 50 elements, inclusive.
  • orange will contain between 1 and 50 elements, inclusive.
  • apple and orange will contain the same number of elements.
  • Each element of apple and orange will be between 0 and 1,000,000, inclusive.
Examples
0)
{1}
{1}
Returns: 3

Three different presents are possible in this case: 0 apples and 1 orange 1 apple and 0 oranges 1 apple and 1 orange

1)
{1, 2, 0, 3}
{4, 5, 0, 6}
Returns: 0

As there is an empty bag, there is no way to choose the present.

2)
{2, 2, 2}
{2, 2, 2}
Returns: 16
3)
{7, 4, 5}
{1, 10, 2}
Returns: 46
4)
{1000000}
{1000000}
Returns: 1000002000000

Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class WinterAndPresents with a public method long long getNumber(vector<int> apple, vector<int> orange) · 66 test cases · 2 s / 256 MB per case

Submitting as anonymous