CF1307E.Cow and Treats
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass!
On the field, there is a row of n units of grass, each with a sweetness si . Farmer John has m cows, each with a favorite sweetness fi and a hunger value hi . He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner:
- The cows from the left and right side will take turns feeding in an order decided by Farmer John.
- When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats hi units.
- The moment a cow eats hi units, it will fall asleep there, preventing further cows from passing it from both directions.
- If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset.
Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them.
Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 109+7 )? The order in which FJ sends the cows does not matter as long as no cows get upset.
输入格式
The first line contains two integers n and m ( 1≤n≤5000 , 1≤m≤5000 ) — the number of units of grass and the number of cows.
The second line contains n integers s1,s2,…,sn ( 1≤si≤n ) — the sweetness values of the grass.
The i -th of the following m lines contains two integers fi and hi ( 1≤fi,hi≤n ) — the favorite sweetness and hunger value of the i -th cow. No two cows have the same hunger and favorite sweetness simultaneously.
输出格式
Output two integers — the maximum number of sleeping cows that can result and the number of ways modulo 109+7 .
输入输出样例
输入#1
5 2 1 1 1 1 1 1 2 1 3
输出#1
2 2
输入#2
5 2 1 1 1 1 1 1 2 1 4
输出#2
1 4
输入#3
3 2 2 3 2 3 1 2 1
输出#3
2 4
输入#4
5 1 1 1 1 1 1 2 5
输出#4
0 1
说明/提示
In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows:
- Cow 1 is lined up on the left side and cow 2 is lined up on the right side.
- Cow 2 is lined up on the left side and cow 1 is lined up on the right side.
In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow:
- Cow 1 is lined up on the left side.
- Cow 2 is lined up on the left side.
- Cow 1 is lined up on the right side.
- Cow 2 is lined up on the right side.
In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows:
- Cow 1 and 2 are lined up on the left side.
- Cow 1 and 2 are lined up on the right side.
- Cow 1 is lined up on the left side and cow 2 is lined up on the right side.
- Cow 1 is lined up on the right side and cow 2 is lined up on the left side.
In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side.