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
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;//注意,都要开longlong 要不然报错
vector<ll>ve[N],vec[N];
int a[N];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
ios::sync_with_stdio(0);
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++) cin>>a[i];
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
ve[y].push_back(x);
}
for(int i=1;i<=m;i++)//将ve转化为fvec,非常关键
{
sort(ve[i].begin(),ve[i].end(),cmp);
long long sum=0;
for(int j=0;j<ve[i].size();j++)//存入vec中,vec的开头是:最少的个数
{
if(j<a[i]) sum+=ve[i][j];
if(j>=a[i]) vec[j+1].push_back(ve[i][j]);
if(j+1==a[i]) vec[j+1].push_back(sum);
}
ve[i].clear();
}
long long mc=0,ms=1,ns,nc=0;
for(int i=1;i<=n;i++)//前后相互比较,非常关键
{
ns=i;
for(int j=0;j<vec[i].size();j++)
{nc+=vec[i][j];}
if(mc*ns<nc*ms) mc=nc,ms=ns;
vec[i].clear();
}
long long k=__gcd(mc,ms);
cout<<mc/k<<'/'<<ms/k<<endl;
}
return 0;
}