#243. 特定条件分组求和

    ID: 243 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatRecursion-2gesp6DFS背包DP

特定条件分组求和

Grouping Sum with Specific Conditions

Background

Congcong has recently been studying how to cleverly group a set of numbers. He wants to know if it's possible to divide these numbers into two groups such that the sum of the two groups is the same, while satisfying specific conditions.

Problem Description

Given an array of integers, determine if it's possible to divide these integers into two groups such that the sum of the two groups is the same. Additionally, the following constraints must be met: all values that are multiples of 55 must be in one group, and all values that are multiples of 33 (and not multiples of 55) must be in the other. (No loops needed.)

Input Format

The input is given from standard input in the following format.

The input consists of a single line containing space-separated integers, representing the elements of an array.

Output Format

Output to standard output in the following format.

Output true if it's possible to divide the integers into two groups with equal sums according to the requirements; otherwise, output false.

Sample

1 1
true
1 1 1
false
2 4 2
true

Sample Explanation

Sample 1: Input 1 1.

  • There are no multiples of 55 or 33 in the array.
  • The total sum is 22, and the target sum for each group is 11.
  • We can put the first 11 into group 1 and the second 11 into group 2. Both groups have a sum of 11, which are equal. So, the output is true.

Sample 2: Input 1 1 1.

  • There are no multiples of 55 or 33 in the array.
  • The total sum is 33. Since the total sum is odd, it cannot be divided into two groups with equal sums. So, the output is false.

Sample 3: Input 2 4 2.

  • There are no multiples of 55 or 33 in the array.
  • The total sum is 88, and the target sum for each group is 44.
  • We can put the first 22 and the third 22 into group 1, making its sum 44; and put 44 into group 2, making its sum 44. The sums of both groups are equal. So, the output is true.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.