Codeforces 1240A. Save the Nature
显然可以二分答案
如果知道卖的票数,那么就能算出有多少 $a$ 倍数但不是 $b$ 倍数的位置,多少 $b$ 倍数但不是 $a$ 倍数的位置,多少既是 $a$ 又是 $b$ 倍数的位置
然后贪心地把每张票分配给那些位置即可
把价格从大到小排序并预处理前缀和就可以 $O(1)$ 求出最大收益了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+;
ll Q,n,p[N],X,Y,A,B,K;
ll sum[N];
ll gcd(ll x,ll y) { return y ? gcd(y,x%y) : x; }
bool check(ll p)
{
ll ab=p/(1ll*A/gcd(A,B)*B),a=p/A-ab,b=p/B-ab;
return sum[ab]/*(X+Y)+(sum[ab+a]-sum[ab])/*X+(sum[ab+a+b]-sum[ab+a])/*Y>=K;
}
int main()
{
Q=read();
while(Q--)
{
n=read();
for(int i=;i<=n;i++) p[i]=read();
sort(p+,p+n+); reverse(p+,p+n+);
for(int i=;i<=n;i++) sum[i]=sum[i-]+p[i];
X=read(),A=read();
Y=read(),B=read();
if(X<Y) swap(X,Y),swap(A,B);
K=read();
ll L=,R=n,Ans=N;
while(L<=R)
{
int mid=L+R>>;
if(check(mid)) Ans=mid,R=mid-;
else L=mid+;
}
if(Ans==N) printf("-1\n");
else printf("%lld\n",Ans);
}
return ;
}
Codeforces 1240A. Save the Nature的更多相关文章
- Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) C. Save the Nature【枚举二分答案】
https://codeforces.com/contest/1241/problem/C You are an environmental activist at heart but the rea ...
- Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) C. Save the Nature
链接: https://codeforces.com/contest/1241/problem/C 题意: You are an environmental activist at heart but ...
- CodeForces 867B Save the problem
B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...
- codeforces 624A Save Luke(水题)
A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CodeForces 937C Save Energy! 水题
题意: 一个炉子烤鸡,炉子打开的时候一共$T$分钟可以烤完,关闭的时候一共$2T$分钟可以烤完,炉子每$K$分钟自动关闭,厨师每$D$分钟回来检查,打开炉子 问多长时间烤完.. 题解: 用整数写比较稳 ...
- Codeforces Round #591 (Div. 2)
A. CME 题目链接:https://codeforces.com/contest/1241/problem/A 题意: 你有 N 根火柴 , 多少根火柴就可以组成多大的数(如 三根火柴可以表示 3 ...
- Codeforces Round #591
目录 Contest Info Solutions A. Save the Nature B. Sequence Sorting C. Paint the Tree D. Stack Extermin ...
- Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)
Virtual participate 的,D题不会做,打了1:30就打不动了,过了ABCE. A - CME 题意:? 题解:? void test_case() { int n; scanf(&q ...
- Technocup 2020 - Elimination Round 1补题
慢慢来. 题目册 题目 A B C D tag math strings greedy dp 状态 √ √ √ √ //∅,√,× 想法 A. CME res tp A 题意:有\(n\)根火柴,额外 ...
随机推荐
- mysql 1045 - Access denied for user 'root'@'*.*.*.*' (using password YES)
远程无法连接mysql 解决方法: 1.在服务器登录数据 mysql -uroot -hlocalhost -P3306 -p Enter password: Welcome to the MySQL ...
- react-hook的简单的动画插件react-simple-animate(其实是react插件,但是这里只介绍react-hook的简单用法)
1.useAnimate(普通anima动画的形式) (1)js const animate = useAnimate({ complete: { display: 'none' }, //动画完成的 ...
- 数据结构之双端队列(Deque)
1,双端队列定义 双端队列:其两端都可以入列和出列的数据结构,如下图所示,队列后面(rear)可以加入和移出数据,队列前面(front)可以加入和移出数据 双端队列操作: deque=Deque() ...
- vsCoad设置代码自动换行
- shiro中接入单点登录功能
最近新建的系统中使用了shiro,而shiro框架中包含登录认证和鉴权的功能,因为我们系统要统一接入公司内部的单点登录(isso)系统,所以通过isso的登录用户,需要在shiro中置为已认证,一下提 ...
- vue3.x版本安装element-ui、axios及echarts图表插件
项目中安装使用element-UI 命令行: vue add element 安装成功后,项目会自动将element-UI引入项目中,刷新项目即可 项目中安装使用axios数据请求 vue add a ...
- Java日志体系(八)最佳实践
java常用日志框架关系 Log4j 2与Log4j 1发生了很大的变化,Log4j 2不兼容Log4j 1. Logback必须配合Slf4j使用.由于Logback和Slf4j是同一个作者,其兼容 ...
- React Native pod install报错 `Yoga (= 0.44.3.React)` required by `React/Core (0.44.3)`
使用pod安装,可能会因为Podfile的路径指向错误或者没有路径指向因为报错. 报错截图如下: 这是因为在指定的路径没有寻找到相应的组件.此时就需要修改podfile文件中的路径,由于上方提示没有 ...
- 整合AD RMS与EX 2010。
1.点击开始菜单, 选择所有程 序,展开 Mi cros oft Excha nge Server 2010 ,打开Excha nge Ma na gement Cons ol e,选择收件人配 ...
- SecureCRT 8.3注册码下载
SecureCRT注册码是一款针对“SecureCRT 8.3”软件而制作的激活破解工具,可以完美激活“SecureCRT”软件,从而达到免费使用的目的.而SecureCRT则是一款非常优秀的且支持s ...