Codeforces--967B--Watering System

51 篇文章 0 订阅

题目描述:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for n flowers and so it looks like a pipe with n holes. Arkady can only use the water that flows from the first hole.

Arkady can block some of the holes, and then pour A liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes s1,s2,…,sn. In other words, if the sum of sizes of non-blocked holes is S, and the i-th hole is not blocked, si⋅AS liters of water will flow out of it.

What is the minimum number of holes Arkady should block to make at least B liters of water flow out of the first hole?
输入描述:
The first line contains three integers n, A, B (1≤n≤100000, 1≤B≤A≤104) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.

The second line contains n integers s1,s2,…,sn (1≤si≤104) — the sizes of the holes.
输出描述:
Print a single integer — the number of holes Arkady should block.
输入:
4 10 3
2 2 2 2
4 80 20
3 2 1 4
5 10 10
1000 1 1 1 1
输出:
1
0
4
题意:
有n个出水口,第i个出水口的出水量为,在入水口加入A的水量,问你至少堵掉多少出水口才能使第一个水管出水量至少为B。出水量计算公式,S表示未堵掉出水口出水量之和。
题解
排序后从后往前找就好了
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn = 100000 + 5;
int n,a,b;
int c[maxn];

int main(){
    while(scanf("%d%d%d",&n,&a,&b)!=EOF){
        int sum = 0;
        for(int i = 1; i <= n; i ++){
            scanf("%d",&c[i]);
            sum += c[i];
        }
        if(n == 1){
            printf("0\n");
            continue;
        }
        sort(c + 2,c + n + 1);
        if(c[1] * a / sum >= b) printf("0\n");
        else{
            for(int i = n; i >= 2; i --){
                sum -= c[i];
                if(c[1] * a / sum >= b){
                    printf("%d\n",(n - i + 1));
                    break;
                }
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值