远端评测题 1000ms 32MiB

[COCI 2008/2009 #2] PERKET

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Background

Description

Perket is a popular dish. To make a good Perket, the chef must choose the ingredients carefully to achieve the most balanced flavor while keeping the traditional taste. You have nn available ingredients. For each ingredient, we know its sourness ss and bitterness bb. When we add ingredients, the total sourness is the product of the sourness values of the chosen ingredients; the total bitterness is the sum of the bitterness values of the chosen ingredients.

It is well known that a good dish should be well balanced, so we want to choose a subset of ingredients that minimizes the absolute difference between the total sourness and the total bitterness.

Also, we must add at least one ingredient, because no dish is made with only water.

Problem Description

Perket is a popular dish. To make a good Perket, the chef must choose the ingredients carefully to achieve the most balanced flavor while keeping the traditional taste. You have nn available ingredients. For each ingredient, we know its sourness ss and bitterness bb. When we add ingredients, the total sourness is the product of the sourness values of the chosen ingredients; the total bitterness is the sum of the bitterness values of the chosen ingredients.

It is well known that a good dish should be well balanced, so we want to choose a subset of ingredients that minimizes the absolute difference between the total sourness and the total bitterness.

Also, we must add at least one ingredient, because no dish is made with only water.

Description

Input Format

The first line contains an integer nn, the number of available ingredient types. The next nn lines each contain 22 integers sis_i and bib_i, the sourness and bitterness of the ii-th ingredient.

Output Format

Output a single integer: the minimum possible absolute difference between the total sourness and the total bitterness.

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

Hint

For the third sample, choose the last three ingredients. Then the total sourness is 2×3×4=242 \times 3 \times 4 = 24, the total bitterness is 6+8+9=236+8+9=23, and the difference is 11.

Constraints

  • For 100%100\% of the testdata, 1n101 \leq n \leq 10, and the total sourness and the total bitterness obtained by using all available ingredients are less than 1×1091 \times 10^9.

Notes

  • This problem is worth 7070 points.
  • Translated from COCI2008-2009 CONTEST #2 PERKET, translator
    https://www.luogu.com.cn/user/115711

Translated by ChatGPT 5

第 22 课:枚举算法-子集枚举

未认领
状态
已结束
题目
11
开始时间
2026-7-2 17:00
截止时间
2026-7-17 17:00
可延期
24 小时