传送门

显然可以二分答案

如果知道卖的票数,那么就能算出有多少 $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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. CodeForces 867B Save the problem

    B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...

  4. codeforces 624A Save Luke(水题)

    A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. CodeForces 937C Save Energy! 水题

    题意: 一个炉子烤鸡,炉子打开的时候一共$T$分钟可以烤完,关闭的时候一共$2T$分钟可以烤完,炉子每$K$分钟自动关闭,厨师每$D$分钟回来检查,打开炉子 问多长时间烤完.. 题解: 用整数写比较稳 ...

  6. Codeforces Round #591 (Div. 2)

    A. CME 题目链接:https://codeforces.com/contest/1241/problem/A 题意: 你有 N 根火柴 , 多少根火柴就可以组成多大的数(如 三根火柴可以表示 3 ...

  7. Codeforces Round #591

    目录 Contest Info Solutions A. Save the Nature B. Sequence Sorting C. Paint the Tree D. Stack Extermin ...

  8. 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 ...

  9. Technocup 2020 - Elimination Round 1补题

    慢慢来. 题目册 题目 A B C D tag math strings greedy dp 状态 √ √ √ √ //∅,√,× 想法 A. CME res tp A 题意:有\(n\)根火柴,额外 ...

随机推荐

  1. 事件处理机制与Handler消息传递机制

    一.基于监听的事件处理机制 基于监听的时间处理机制模型: 事件监听机制中由事件源,事件,事件监听器三类对象组成 处理流程如下: Step 1:为某个事件源(组件)设置一个监听器,用于监听用户操作 St ...

  2. 5.使用Ribbon实现客户端侧负载均衡

                                Ribbon实现客户端侧负载均衡 5.1. Ribbon简介 Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法 ...

  3. Netfilter 之 iptable_nat

    初始化 iptable_nat_table_init函数通过调用ipt_register_table完成NAT表注册和钩子函数注册的功能:该流程与iptable_filter的函数调用的函数一致,此处 ...

  4. Appnium安装

    Refer to https://blog.csdn.net/xgh1951/article/details/85124327

  5. java 日志文件打印

    java中的日志打印   java中的日志打印: 日志工具类:   log4j.properties解释: 1 1.输出级别的种类 2 ERROR.WARN.INFO.DEBUG 3 ERROR 为严 ...

  6. ios wkwebview allowFileAccessFromFileURLs

    最近在做 cordova 打包 ios 的项目(webpack 打包 vue项目后,再用 cordova 打包).在加载 file:/// 协议时因为 webview安全机制有一些报错.SK各种找解决 ...

  7. linux系统中的一些典型问题汇总

    一.文件系统破坏导致系统无法启动:Checking root filesystem/dev/sda6 contains a file system with errors,check forcedAn ...

  8. Python3 编程第一步_关键字end

    关键字end可以被用于防止输出新的一行,或者在输出的末尾添加不同的字符: a, b = 0, 1 while b < 1000: print(b, end=',') a, b = b, a+b ...

  9. Docker在PHP项目开发环境中的应用

    http://avnpc.com/pages/build-php-develop-env-by-docker

  10. 关于Bootstrap Table使用生成冻结窗格的表格

    参考资料 : <JS组件系列——Bootstrap Table 冻结列功能IE浏览器兼容性问题解决方案> <http://issues.wenzhixin.net.cn/bootst ...