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\)根火柴,额外 ...
随机推荐
- PDB GDB 调试代码
https://blog.csdn.net/zdy0_2004/article/details/80102076 https://www.jianshu.com/p/fb5f791fcb18
- requests_html使用asyncio
import asyncio import functools from concurrent.futures.thread import ThreadPoolExecutor from reques ...
- Jinja2学习
模板: 知名模板引擎:jinja2(flask默认的模板引擎) Mako template模板路径: 1.在渲染模板的时候,会默认从根目录下的templates目录下查找模板文件 2.也可以自定义模板 ...
- Flume-Exec Source 监控单个本地文件
实时监控,并上传到 HDFS 中. 一.Flume 要想将数据输出到 HDFS,须持有 Hadoop 相关 jar 包 若 Hadoop 环境和 Flume 在同一节点,那么只要配置 Hadoop 环 ...
- Nginx优化之服务性能优化
优化Nginx服务的worker进程个数 修改nginx主配置文件 worker_processes 1; #指定了Nginx要开启的进程数,结尾数字就是进程个数 Nginx有Master进程和wor ...
- css 添加一个图标始终保持在pc端的右下角
<div class="dialog_maxdiv" style="display:block;"> <div id="center ...
- Django运行项目时候出现DisallowedHost at / Invalid HTTP_HOST header:
web端错误现象: DisallowedHost at / Invalid HTTP_HOST header: 'ip:8000'. You may need to add u'ip' to ALLO ...
- Linux命令集锦:crontab命令
Linux crontab是用来定期执行程序的命令.当安装完成操作系统之后,默认便会启动此任务调度命令.crontab命令每分钟会定期检查是否有要执行的工作,如果有要执行的工作便会自动执行该工作. 而 ...
- jekins自动部署tomcat注意事项、连接tomcat报错
jekins自动部署tomcat注意事项 千万不要用下面插件推送,报错很多, 要用脚本,一篇博客说的:“我们都是用的脚本,插件报错太多,也不完善” Deploy to container Plugin ...
- laravel如何打印orm封装的sql语句
$query = CdbForumSellthreadSearch::where($params)->orderBy("$orderby", "$ascDesc&q ...