No.14 Download More RAM

题目来源:

https://acs.jxnu.edu.cn/contest/23/board/challenge/Cicon-default.png?t=M0H8https://acs.jxnu.edu.cn/contest/23/board/challenge/C

原文:

Download More RAM

描述:

Did you know you can download more RAM? There is a shop with nn different pieces of software that increase your RAM. The ii-th RAM increasing software takes aiai GB of memory to run (temporarily, once the program is done running, you get the RAM back), and gives you an additional bibi GB of RAM (permanently). Each software can only be used once. Your PC currently has kk GB of RAM.

Note that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have.

Since RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable?

输入:

The first line of the input contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. The description of test cases follows.

The first line of each test case contains the integers nn and kk (1≤n≤1001≤n≤100, 1≤k≤10001≤k≤1000). Then two lines follow, each containing nn integers describing the arrays aa and bb (1≤ai,bi≤10001≤ai,bi≤1000).

输出:

For each test case, output a single line containing the largest amount of RAM you can achieve.

样例输入:

4
3 10
20 30 10
9 100 10
5 1
1 1 5 1 1
1 1 1 1 1
5 1
2 2 2 2 2
100 100 100 100 100
5 8
128 64 32 16 8
128 64 32 16 8

样例输出:

29
6
1
256

参考译文:

获取更多的内存

描述:

你知道怎样才能获取更多的内存吗?已知应用商城里有n款软件可以扩大你的内存。每款软件需要一定的运行内存a GB,需要注意的是,只有在软件运行结束时你才能获取软件提供的相应的内存b GB,且每款应用软件只有第一次使用可以增加你的内存,已知你的电脑现在有k GB的内存。

注意,如果你现有的内存不足以使软件运行,你将无法获得相应的内存。

因为内存是非常重要的东西,所以你需要知道你的电脑能拥有的最大内存是多少?

输入:

第一行包含一个整数t,表示测试的组数,每组测试描述如下:

每组测试的第一行包含两个整数n 和k (1≤n≤1001≤n≤100, 1≤k≤10001≤k≤1000),接下来两行,每行包含n 个整数,用来表示每款软件的运行内存a和获取内存b (1≤ai,bi≤10001≤ai,bi≤1000)。

输出:

每组测试对应一行输出,包含一个整数,用于表示你的电脑能拥有的内存最大数。

样例输入:

4
3 10
20 30 10
9 100 10
5 1
1 1 5 1 1
1 1 1 1 1
5 1
2 2 2 2 2
100 100 100 100 100
5 8
128 64 32 16 8
128 64 32 16 8

样例输出:

29
6
1
256

参考代码:

#include<iostream>
#include<algorithm>
using namespace std;
struct RAM{
	int a;
	int b;
}; 
int compare( const void * a, const void * b )
{
	return ( *(int*) a - *(int*) b );
} 

int main()
{
	int t;
	cin >> t;
	for(int i = 0;i < t;++i){
		int m,n;
		cin >> m >> n;
		struct RAM ram[m];
		for(int j = 0;j < m;++j){
			cin >> ram[j].a;
		}
		for(int j = 0;j < m;++j){
			cin >> ram[j].b;
		}//输入部分 
		
		qsort(ram,m,2*sizeof(int),compare);
		for(int j = 0;j < m;++j){
			if(ram[j].a <= n){
				n += ram[j].b;
			}
			//cout << ram[j].a << " " << ram[j].b << endl;
		}
		cout << n << endl;
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乌凌丢了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值