题目来源:
https://acs.jxnu.edu.cn/contest/23/board/challenge/Chttps://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;
}
}