D. Dynamic Problem Scoring
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.

For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.

Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.

If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.

There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.

With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.

Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.

Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.

Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.

Input

The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.

Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.

It is guaranteed that each participant has made at least one successful submission.

Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.

Output

Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.

Examples
input
2
5 15 40 70 115
50 45 40 30 15
output
2
input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
output
3
input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
output
27
input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
output
-1
Note

In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.

In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.

In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.

心态炸了,这道题暴力可以过啊,忧伤。。。。也就是读懂提议基本就可以了,两个人比赛呢,用的是CF这种分数赛制林林总总的,英语太重要啦

#include<bits/stdc++.h>
using namespace std;
int a[][];
int cnt[];
int n;
int getsc(int id, bool f, int s) {
if(a[f][id]==-) return ;
int sum;
if(a[][id] == - || a[][id] == - || a[][id]<a[][id]) sum = cnt[id];
else sum = cnt[id]+s;
int sc = ;
for(int i = ; i <= ; i*=) {
if(sum*i > n+s)
break;
else sc += ;
}
return sc*(250.0 - a[f][id])/250.0;
}
int main() {
cin >> n;
for(int i = ; i < n; ++i)
for(int j = ; j < ; ++j) {
cin >> a[i][j];
if(a[i][j]!= -)
cnt[j]++;
}
for(int i = ; i < ; ++i) {
int a1=, a2=;
for(int j = ; j < ; ++j)
a1 += getsc(j, , i);
for(int j = ; j < ; ++j)
a2 += getsc(j, , i);
if(a1 > a2) {
cout << i << endl;
return ;
}
}
cout << "-1" <<endl;
return ;
}

Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring的更多相关文章

  1. Codeforces Round #585 (Div. 2) [补题]

    前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...

  2. Codeforces Round #786 (Div. 3) 补题记录

    小结: A,B,F 切,C 没写 1ll 对照样例才发现,E,G 对照样例过,D 对照样例+看了其他人代码(主要急于看后面的题,能调出来的但偷懒了. CF1674A Number Transforma ...

  3. Codeforces Round #429 (Div. 2) 补题

    A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...

  4. Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

    A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...

  5. Codeforces Round #590 (Div. 3)补题

    要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ∅ √ 解 E 待定 F 传送门 第一 ...

  6. Codeforces Round #574 (Div. 2)补题

    A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 >  Σki / 2 ? (n + 1)/2 - Σki / ...

  7. Codeforces Round #615 (Div. 3) 补题记录

    第一次搞CF,结果惨不忍睹...还是太菜了 A:要用到全部的钱,所以总数必须是3的倍数,而且初始状态下任意一人的钱数不能超过总数除以3,否则没法分了 (也就这个签到算是在我能力范围之内了....) # ...

  8. Codeforces Round #617 (Div. 3) 补题记录

    1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...

  9. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

随机推荐

  1. MediaRecord一些使用记录

    今天学习了MediaRecord的使用,第一次使用做个记录. MediaRecord作用是声音录制,使用步骤如下: 1.新建出音频文件代码如下: 先创建出用于存储音频文件 File dir = new ...

  2. sqlite总结1

    I Shell下命令行程序CLP I .help II 命令的简写 .e = .quit .s .h = .help II 数据库管理 A 创建数据库 1 CREATE TABLE id_name(i ...

  3. Java之instanceof

    class Base{     int x = 1;     static int y = 2;     String name(){         return "mother" ...

  4. Spring下读取properties文件

    由于在spring的xml文件中配置了 <bean id="validator" class="org.springframework.validation.bea ...

  5. selenium-Python之定位下拉框选择

    1.通过select 进行定位下拉框 下拉框如图所示 通过代码定位 #通过index进行选择Select(driver.find_element_by_id("cardType") ...

  6. UIButton 左对齐 省略号最右边

    //左对齐 [_btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; //省略号靠右侧 _btn.ti ...

  7. access处理重复创建表的方法。

    第一种,使用MSysObjects表查找表名为当前创建表的名字的内容,相当于普通查询,但是access数据库有一个安全问题,就是有时候一开始是没有权限去调这些系统表的,这时可以再2007的access ...

  8. 使用crontab定时执行python文件问题追根溯源

    使用crontab执行定时任务不是第一次用,昨天下午设置几个任务,yy里面已存在的任务,修改指定python环境和执行文件路径后,死活到点不执行. 任务设置如下: 15 16 * * * /root/ ...

  9. CAD交互绘制矩形批注(网页版)

    js中实现代码说明: 动态拖放时的绘制事件: function DynWorldDrawComment2( pCustomEntity,pWorldDraw, curPt) { // 得到绘制参数. ...

  10. shell脚本,计算学生分数的题目。

    1.计算学生平均分数的值是多少? 2.计算每门课都大于80分的学生姓名.3.计算每门课都小于90分的学生姓名.