Codeforce---------Watering System

Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for nn flowers and so it looks like a pipe with nn holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour AA liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes s1,s2,…,sns1,s2,…,sn. In other words, if the sum of sizes of non-blocked holes is SS, and the ii-th hole is not blocked, si⋅ASsi⋅AS liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least BB liters of water flow out of the first hole?
InputThe first line contains three integers nn, AA, BB (1≤n≤1000001≤n≤100000, 1≤B≤A≤1041≤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 nn integers s1,s2,…,sns1,s2,…,sn (1≤si≤1041≤si≤104) — the sizes of the holes.
OutputPrint a single integer — the number of holes Arkady should block.
Examples
Input
4 10 3
2 2 2 2
Output
1
Input
4 80 20
3 2 1 4
Output
0
Input
5 10 10
1000 1 1 1 1
Output
4
题目大意:一个水管有n个水孔,一共有a L水,最少需要b L水
A first output of the first aperture size of the water, and then sequentially input aperture size of each of water, water can block holes, water holes required minimum number of block can be output from the first water hole liters minimum b. Water from the water holes each output depends on the proportion of water pore size

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1e5 + 10;
int q[N];
int main(){
 int n, a, b, c;
 scanf("%d%d%d",&n, &a, &b);
 scanf("%d",&c);
 int sum = c;
 for (int i = 0; i < n - 1; i ++){
  scanf("%d",&q[i]);
  sum += q[i]; 
 }
  sort(q , q + n - 1);
 reverse(q, q + n - 1);
  int ans = 0;
 if (a * c / sum >= b)   ans = 0;
 else{
  for (int i = 0; i < n - 1; i ++){
   if (a * c / sum >= b)   break;
   sum -= q[i];
   ans ++;
  }
 }
 printf("%d\n",ans);
  return 0; 
}
Published 106 original articles · won praise 67 · views 5440

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/104741568