易如反掌吗
2024-02-24 11:31:32
发布于:广东
9阅读
0回复
0点赞
把难度从小到大排序,这样的话如果打不过前面的,那后面的就绝对打不过
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
int level, price;
}a[1005];
int ans[105], ct;
bool cmp(node a, node b){
return a.level < b.level;
}
int main(){
int t, n, k;
scanf("%d", &t);
while(t--){
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++) scanf("%d", &a[i].level);
for(int i = 1; i <= n; i++) scanf("%d", &a[i].price);
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i++){
if(k >= a[i].level) k += a[i].price;
else break;
}ans[++ct] = k;
}for(int i = 1; i <= ct; i++) printf("%d\n", ans[i]);
return 0;
}
这里空空如也
有帮助,赞一个