B. Balanced Diet(前缀数组+贪心)

Gym_102220_B_Balanced Diet

B. Balanced Diet
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output

Taylor is wandering in a milk candy store. The store has m types of sweets and there are n sweets in the store. The i-th sweet has the value of ai, and it is of type bi.

Taylor is planning to buy some sweets in the store, each sweet can be bought at most once. He will buy at least one sweet. Taylor knows that a balanced diet is important, the value of a sweet set is measured as S/C, where S denotes the sum of ai and C denotes the maximum number of occurrences among all types of sweets.

Assume Taylor selects pi sweets of type i, it is not welcomed if 1≤pi<li. Note that pi can also be 0 and pi can be everything when li=1.

Please write a program to help Taylor find the sweet set with maximum value.

Input
The first line of the input contains an integer T(1≤T≤1000), denoting the number of test cases.

In each test case, there are two integers n,m(1≤n,m≤100000) in the first line, denoting the number of sweets and types.

In the second line, there are m integers l1,l2,…,lm(1≤li≤n).

For the next n lines, each line contains two integers ai,bi(1≤ai≤108,1≤bi≤m), denoting each sweet.

It is guaranteed that ∑n≤106 and ∑m≤106, and there always exists a valid sweet set.

Output
For each test case, print a single line of format u/v, denoting the maximum value uv. Note that you should guarantee that gcd(u,v)=1.

Example
Input

2
2 1
2
7 1
2 1
3 2
1 2
2 1
5 2
3 2

Output

9/2
5/1

题目大意

自己好菜呀!这个题意读了好久才明白。先是给你一个数 T 有T组数据!
每组数据 给了 N和M表示有M种类型的糖果,这些糖果一共N个。
接下了是 M 组数据,表示如果你选第 i 中糖果,那么你最少选 Li (你也可以不选),
再接下来就是 N 行数据,每一行 ai 和 bi 表示这个糖果属于 bi 这个种类的,它的价值是ai。
最后让你输出你挑选的糖果的总价值除以 你取得糖果中数量最多的那种糖果的数量,然后化成最简分数ÿ

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值