当前位置: 首页 > 工具软件 > Fire > 使用案例 >

You Are Fired!

梁福
2023-12-01

The latest quarterly report of the Pump Organization does not look promising at all: the costs exploded while the revenue decreased by 42%. Taking a closer look at the numbers, CEO Dagobert J. Pump comes to the conclusion that the only way to save the company is to fire some of the employees.
The problem is that CEO Pump just recently claimed in an interview that “he is the greatest job creator that God ever created”. So if he fired too many people, the dishonest corrupted left-wing media would certainly report about it, which would make him look extremely unreliable. The PR experts of the Pump Organization already estimated a number of employees that CEO Pump may fire without raising any attention in the media. To be on the safe side, CEO Pump further decides to fire as few employees as possible.
Taking a list of all employees of his company and their respective salary, CEO Pump has to save at least d Dollars by firing not more than k employees. If this is possible, CEO Pump wants to personally tell each and every one of them: YOU ARE FIRED!

输入
The input consists of:
• one line with three integers n, d, and k, where
– n (1 ≤ n ≤ 10 000) is the number of employees of the Pump Organization;
– d (1 ≤ d ≤ 109 ) is the amount of money that CEO Pump needs to save at least;
– k (1 ≤ k ≤ n) is the maximum number of employees that CEO Pump can fire
without raising attention in the media.
• n lines each containing a string s i and an integer ci , where
– si (1 ≤ |si | ≤ 7) is the name of the i-th employee;
– ci (1 ≤ ci ≤ 100 000) is the salary of the i-th employee.
All si are distinct and only contain lowercase and uppercase letters of the English alphabet.

输出
If there is no way to save at least d Dollars by firing not more than k employees, output impossible.
If there is a way to save at least d Dollars by firing not more than k employees, then the output one line containing a single integer x (1 ≤ x ≤ k), where x is the number of people to be fired.

样例输入
复制样例数据
5 2000 3
John 999
Lyndon 450
Richard 1234
Gerald 1001
Jimmy 300

样例输出
2

简单模拟按金额从大到小排序

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
	string s;
	int num;
}a[100005];
bool cmp(node a,node b)
{
	return a.num>b.num;
}
int main()
{
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++)  cin>>a[i].s>>a[i].num;
	sort(a+1,a+1+n,cmp);
	int sum=0;
	int p=0;
	int i;
	for( i=1;i<=n;i++)
	{
		m-=a[i].num;
		if(m<=0) break;
	}
	if(i>k) puts("impossible");
	else printf("%d\n",i);
	return 0;
 } 
 类似资料:

相关阅读

相关文章

相关问答