传送门

显然可以二分答案

如果知道卖的票数,那么就能算出有多少 $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. CF258B

    CF258B 题意: 7个人在 $ [1,m] $ 区间内取数,求第一个人选的数的4和7的个数大于其他人的4和7个数总和的方案数. 解法: 要求输入的 $ m $ 可以很大,而且需要按位考虑每隔人的贡 ...

  2. Linux kernel device mapper

    Device Mapper 是 Linux2.6 内核中支持逻辑卷管理的通用设备映射机制,它为实现用于存储资源管理的块设备驱动提供了一个高度模块化的内核架构,如图 1. 图1 Device Mappe ...

  3. Netfilter 之 连接跟踪钩子函数分析

    ipv4_conntrack_defrag ipv4_conntrack_defrag对输入包进行检查,如果是分片包,则调用nf_ct_ipv4_gather_frags函数进行重组: static ...

  4. Laravel 代码开发最佳实践

    我们这里要讨论的并不是 Laravel 版的 SOLID 原则(想要了解更多 SOLID 原则细节查看这篇文章)亦或是设计模式,而是 Laravel 实际开发中容易被忽略的最佳实践. 内容概览 单一职 ...

  5. sql_monitor实时监控

    1 检查数据库是否启用了监控功能 1)检查参数:CONTROL_MANAGEMENT_PACK_ACCES SQL> show parameter CONTROL_MANAGEMENT_PACK ...

  6. 异常值检验实战1--风控贷款年龄变量(附python代码)

    python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...

  7. shift and add算法相关

    1.超分辨率 非均匀插值 Farsiu S, Robinson D, Milanfar P. Robust shift and add approach to superresolution[J]. ...

  8. hive数据类型1

  9. centos7安装kvm及kvm管理

    一.安装kvm 查看CPU是否支持虚拟化  grep -E 'svm|vmx' /proc/cpuinfo - vmx is for Intel processors - svm is for AMD ...

  10. Django之权限(起步)

    一. 权限概述 1. 认识权限 为什么要有权限? 因为权限让不同的用户拥有不同的功能. 权限可以对功能进行划分. 生活中处处有权限. 比如, 腾讯视频会员才有观看某个最新电影的权限, 你有房间钥匙就有 ...