100802: [AtCoder]ABC080 C - Shopping Street

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already $N$ stores in the street, numbered $1$ through $N$.

You are given information of the business hours of those shops, $F_{i,j,k}$. If $F_{i,j,k}=1$, Shop $i$ is open during Period $k$ on Day $j$ (this notation is explained below); if $F_{i,j,k}=0$, Shop $i$ is closed during that period. Here, the days of the week are denoted as follows. Monday: Day $1$, Tuesday: Day $2$, Wednesday: Day $3$, Thursday: Day $4$, Friday: Day $5$. Also, the morning is denoted as Period $1$, and the afternoon is denoted as Period $2$.

Let $c_i$ be the number of periods during which both Shop $i$ and Joisino's shop are open. Then, the profit of Joisino's shop will be $P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}$.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

  • $1≤N≤100$
  • $0≤F_{i,j,k}≤1$
  • For every integer $i$ such that $1≤i≤N$, there exists at least one pair $(j,k)$ such that $F_{i,j,k}=1$.
  • $-10^7≤P_{i,j}≤10^7$
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

$N$
$F_{1,1,1}$ $F_{1,1,2}$ $...$ $F_{1,5,1}$ $F_{1,5,2}$
$:$
$F_{N,1,1}$ $F_{N,1,2}$ $...$ $F_{N,5,1}$ $F_{N,5,2}$
$P_{1,0}$ $...$ $P_{1,10}$
$:$
$P_{N,0}$ $...$ $P_{N,10}$

Output

Print the maximum possible profit of Joisino's shop.


Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop $1$ is opened, the profit will be $8$, which is the maximum possible profit.


Sample Input 2

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.


Sample Input 3

3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7

Sample Output 3

23

Input

题意翻译

## 题目描述 Joisino计划要在商店街开一家店。 这家店在周一到周五的$5$ 个工作日都有营业,其中每个工作日又被划分成上午和下午$2$ 个时间段,也就是共有$10$ 个时间段。当然,至少要有$1$ 个时间段这家店营业。 商店街原来有$N$ 个店铺,从$1$ 到$N$ 编号。 这些店铺的营业时间将以$F_{i,j,k}=1$ 的形式给出。如果$F_{i,j,k}=1$ ,第$i$ 家店将在第$j$ 天的第$k$ 个时间段营业。在这里,我们这样定义:第$1$ 天是周一,第$2$ 天是周二,第$3$ 天是周三,第$4$ 天是周四,第$5$ 天是周五。同样的,第$1$ 个时间段是上午,第$2$ 个时间段是下午。 设$c_i$ 为第$i$ 家店和Joisino的店同时营业的时间段数,则Joisino商店的收益将会是$P_{1,c1}+P_{2,c2}+...+P_{N,cN}$ 。 请决定Joisino在这$10$ 个时间段分别是否营业,并求出Joisino商店可能的最大收益,且保证它至少要有$1$ 个时间段营业。 ## 输入输出格式 ### 输入格式 第一行,一个整数$N$ 。 接下来$N$ 行,第i行有10个整数,分别表示$F_{i,1,1}, F_{i,1,2}, ..., F_{i,5,1}, F_{i,5,2}$ 。 再接下来$N$ 行,第i行有11个整数,分别表示$P_{i,0}, ..., P_{i, 10}$ 。 ### 输出格式 只有一行,一个整数,表示Joisino商店可能的最大收益。 ## 说明 ### 样例解释1 如果商店仅在第$1$ 家店营业时营业,收益将会是$8$ ,这是可能的最大收益。 ### 样例解释2 由于必须至少有一个时间段商店营业,所以收益可能会是负数。 ### 数据范围 - $1 \leq N \leq 100$ - $0 \leq F_{i,j,k} \leq 1$ - 对所有满足 $1 \leq i \leq N$ 的 $i$ , 总有一对$(j, k)$ 满足$F_{i,j,k}=1$ 。 - $-10^7 \leq P_{i,j} \leq 10^7$ - 所有输入数据均为整数。 by @月见之兔

加入题单

算法标签: