链接:

https://codeforces.com/contest/1241/problem/C

题意:

You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!

You have n tickets to sell. The price of the i-th ticket is pi. As a teller, you have a possibility to select the order in which the tickets will be sold (i.e. a permutation of the tickets). You know that the cinema participates in two ecological restoration programs applying them to the order you chose:

The x% of the price of each the a-th sold ticket (a-th, 2a-th, 3a-th and so on) in the order you chose is aimed for research and spreading of renewable energy sources.

The y% of the price of each the b-th sold ticket (b-th, 2b-th, 3b-th and so on) in the order you chose is aimed for pollution abatement.

If the ticket is in both programs then the (x+y)% are used for environmental activities. Also, it's known that all prices are multiples of 100, so there is no need in any rounding.

For example, if you'd like to sell tickets with prices [400,100,300,200] and the cinema pays 10% of each 2-nd sold ticket and 20% of each 3-rd sold ticket, then arranging them in order [100,200,300,400] will lead to contribution equal to 100⋅0+200⋅0.1+300⋅0.2+400⋅0.1=120. But arranging them in order [100,300,400,200] will lead to 100⋅0+300⋅0.1+400⋅0.2+200⋅0.1=130.

Nature can't wait, so you decided to change the order of tickets in such a way, so that the total contribution to programs will reach at least k in minimum number of sold tickets. Or say that it's impossible to do so. In other words, find the minimum number of tickets which are needed to be sold in order to earn at least k.

思路:

刚开始以为可以一遍解决.看了题解发现是二分.

直接对排序后的数组前缀和, 然后记录a, b, lcm(a, b)的个数.

贪心加进去

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10; int Val[MAXN];
LL Sum[MAXN];
LL n, x, y, a, b, lcm;
LL k; bool Check(int mid)
{
int cnta = mid/a;
int cntb = mid/b;
int cnts = mid/lcm;
cnta -= cnts, cntb -= cnts;
LL sum = 0;
sum += (Sum[cnts]/100)*(x+y);
sum += ((Sum[cnts+cnta]-Sum[cnts])/100)*x;
sum += ((Sum[cnts+cnta+cntb]-Sum[cnts+cnta])/100)*y;
if (sum >= k)
return true;
return false;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> Val[i];
cin >> x >> a;
cin >> y >> b;
cin >> k;
if (x < y)
swap(x, y), swap(a, b);
sort(Val+1, Val+1+n, greater<int>());
Sum[0] = 0;
for (int i = 1;i <= n;i++)
Sum[i] = Sum[i-1]+Val[i];
lcm = (a*b)/__gcd(a, b);
int l = 1, r = n, res = n+1;
while (l <= r)
{
int mid = (l+r)/2;
if (Check(mid))
{
res = min(res, mid);
r = mid-1;
}
else
l = mid+1;
}
if (res == n+1)
puts("-1");
else
printf("%d\n", res);
} return 0;
}

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) C. 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) D. Sequence Sorting

    链接: https://codeforces.com/contest/1241/problem/D 题意: You are given a sequence a1,a2,-,an, consistin ...

  3. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) B. Strings Equalization

    链接: https://codeforces.com/contest/1241/problem/B 题意: You are given two strings of equal length s an ...

  4. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) A. CME

    链接: https://codeforces.com/contest/1241/problem/A 题意: Let's denote correct match equation (we will d ...

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

  6. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) 题解

    A..B略 C 对当前的值排序,再二分答案,然后对于(i%x==0 && i%y==0)放入大的,再放其他的贪心解决即可. #include<iostream> #incl ...

  7. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

    A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...

  8. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

    A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最 ...

  9. 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...

随机推荐

  1. Centos7 添加开机启动服务

    1.在/usr/lib/systemd/system/下创建服务脚本xxx.service,格式如下: [Unit] Description=Scrapyd After=syslog.target n ...

  2. 【AtCoder】ARC061

    ARC061 C - たくさんの数式 / Many Formulas 这个其实\(10^5\)也能做.. 就是\(dp[i]\)表示到第i位的方案数,\(sum[i]\)表示延伸到第i位之前的所有方案 ...

  3. QT 打包exe

    QT打包主要方法: 1.把无措的代码进行Release编译 2.在运行完后,找到运行后生成的目录,以下是我的文件,名为result,运行类型有两种,一种是Debug,另一种是Release,我们需要的 ...

  4. java项目上线的流程(将web项目部署到公网)

    本博文来源于网络,原文的地址在本篇博文最下方. 如何将java web项目上线/部署到公网 关于如何将Java Web上线,部署到公网,让全世界的人都可以访问的问题.小编将作出系列化,完整的流程介绍. ...

  5. vue中的键盘事件

    @keydown(键盘按下时触发),@keypress(键盘按住时触发),@keyup(键盘弹起) 获取按键的键码 e.keyCode @keyup.13     按回车键 @keyup.enter ...

  6. c# http文件上传

    /// <summary> /// 上传文件的api /// </summary> [HttpPost] public string UploadFile(op_client_ ...

  7. Lua虚拟机中的数据结构与栈

    Lua虚拟机中的数据结构与栈 来源 https://blog.csdn.net/zry112233/article/details/80828327 由上一篇文章可知解释器分析Lua文件之后生成Pro ...

  8. ef core many to many

    https://stackoverflow.com/questions/46184678/fluent-api-many-to-many-in-entity-framework-core/461847 ...

  9. Oracle学习笔记:rank、dense_rank、row_number、ntile等排序算法

    在 oracle 中有很多函数可以实现排序的功能,但是不尽相同.下面一一解说. row_number函数 功能:可实现分组排序,为数据行添加序号,多用于分页查询. 语法:row_number() ov ...

  10. web储存的初级运用

    <html> <head> <meta charset="utf-8"> <title>web存储</title>< ...