题目描述:
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;
}