2019 ICPC-南昌 G题- G. Eating Plan

2019 ICPC-南昌 G题- G. Eating Plan

Bob is hungry now and he needs to eat some food. Alice puts nn dishes of food in front of him, numbered from 11 to nn. Alice tells him that he can only eat continuous dishes of food, or he will be poisoned by food. For example, if there are 1010 dishes, he can eat the food in the 22-nd, 33-rd and 44-th dishes but he can not eat the food in the 22-nd, 33-rd and 55-th dishes because there is the 44-th dish between them so it’s not continuous. Furthermore, if he chooses to eat food in the ii-th dish, he has to eat all food in that dish.

Bob’s stomach has a strange feature that if there is at least t~(=998857459)t (=998857459) kg food in it, the weight in it will reduce tt kg repeatedly until it is strictly lower than tt kg. Also, if the weight of food in his stomach is exactly tt kg, his stomach will be empty. Now Bob wants to eat the smallest number of dishes and remains no less than kk kg food in his stomach. Can you tell him how many dishes he needs to choose?

Input
The first line contains two integers nn and m~(1\leq n\leq 100000,1\leq m\leq 10000)m (1≤n≤100000,1≤m≤10000), indicates the number of dishes and the number of queries.

The second line contains nn integers a_1,a_2,\cdots,a_na
1

,a
2

,⋯,a
n

, which is a permutation of 1, 2, \cdots, n1,2,⋯,n, indicates that there is (a_i!)(a
i

!) kg food in the ii-th dish, where s! = 1 \times 2 \times 3 \times \cdots \times ss!=1×2×3×⋯×s.

The third line contains mm integers, the ii-th integer k_i(1\leq k_i<t)k
i

(1≤k
i

<t) indicates a query with the lower bound of weight.

Output
Each line of mm lines contains an integer indicates the number of dishes Bob needs to choose in that query. If there is no way to reach Bob’s target, output -1 instead.

题意:

一个胖子吃东西,必须吃连续的盘子才行,然后边吃边模上一个t。
我们通过分解可以知道t是一个合数。分解输出来是461,773 ,2803
所以我们大于2802的阶乘都是0。所以我们暴力处理出2083之前的阶乘和。
然后res数组代表每个长度的最大食物重量。暴力过就可以了。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const int N=1e5+5;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值